Read data from a content editor webpart

Jun 11 2010 Published by Hojo Clement under MOSS 2007, Webpart

In this article we will see how we can to get data from a content editor webpart from one page and display it in another page using a custom webpart.

If you are new to webpart development you can check out my previous post about Hello world SharePoint Web Part for Beginners
Add the following code in the RenderWebPartmethod of the webpart you are creating. The code and comments are self explanatory. Please pose a comment if you have any problem in understanding the code.

SPSite site = new SPSite("http://mysite">http://mysite"); // create object of the site
SPWeb web;
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
web = site.OpenWeb();
mgr = web.GetLimitedWebPartManager("Pages/mypage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.User);//http://mysite/Pages/mypage.aspx will be the URL of the source page
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp.Title ==  "My RichTextEditor") //My RichTextEditor is the webpart title
{
SPWebPartPages.ContentEditorWebPart webPart =    (SPWebPartPages.ContentEditorWebPart)wp;
output.Write(webPart.Content.InnerText);
}
}

No responses yet

Create SharePoint pages using Macromedia Dreamweaver Templates(.dwt files)

Apr 19 2010 Published by Radhika under MOSS 2007, SharePoint Design Customisation

We know that web page design using Dreamweaver is very easy, but design customization of SharePoint is really hectic. so how about creating SharePoint pages using Dreamweaver? Here is how you can do it

1. Upload your dwt files,css and images in a document library.

2. Open your site in SharePoint Designer.

3. If you want editable regions in that aspx page, create editable portions in the dwt template using below code

<!-- #BeginEditable "body" -->step 3: File new-->create from dynamic web  template
<!-- #EndEditable -->

Step 4: Choose your dwt file and click on Ok and save the page as somename.aspx.

No responses yet

Webpart Development part 4: Creating Custom Web Part Properties

Apr 05 2010 Published by Hojo Clement under MOSS 2007, Webpart

In recent blog posts we learnt webPart development, deployment  and adding controls etc..

In this blog post we will see how to add custom properties for SharePoint web part. There are several properties available in SharePoint web part for setting its look and feel like Title, Height and Width etc.. In this example we will see how to add Dropdown, Check box and a Text box in webPart tool pane.

  1. Open Visual studio and create a new web part project
  2. Open the .cs file
  3. import the name space System.ComponentModel;
  4. To define the XML namespace to be used for the Custom WebPart, add the below code just above the class declaration. (These values can be whatever you choose and aren’t related to the class name.)
      [DefaultProperty("Text"), ToolboxData("<{0}:WPwithBGcolr runat=server></{0}:DisplayLatestPosts"), XmlRoot(Namespace = "WPwithBGcolr")]
  5. Change the base class from System.Web.UI.WebControls.WebParts.WebParttoMicrosoft.SharePoint.WebPartPages.WebPart
  6. For adding a text box in tool part pane, add the below property in the class
     public string text;
    [Category("Advanced Settings"),
    Personalizable(PersonalizationScope.Shared),
    WebBrowsable, WebDisplayName("Text"),
    WebDescription("Enter your text")]
    public string Text
    {
    get { return text; }
    set { text = value; }
    }
  7. For adding a checkbox in tool part pane you need to add the blow code
    public Boolean border;
    [Category("Advanced Settings"),
    Personalizable(PersonalizationScope.User),
    WebBrowsable, WebDisplayName("Border"),
    WebDescription("Do you want border")]
    public Boolean Border
    {
    get { return border; }
    set { border = value; }
    }
  8. For adding a dropdown in tool part pane , first declare an enum variable and create the property using this new variable as shown in the below code.
    public enum ColorByEnum { Red, Blue, Green };
    protected ColorByEnum colorBy;
    [Category("Advanced Settings"),
    Personalizable(PersonalizationScope.User),
    WebBrowsable,
    WebDisplayName("Background Color"),
    WebDescription("Choose a background color for your webpart")]
    public ColorByEnum ColorBy
    {
    get { return colorBy; }
    set { colorBy = value; }
    }
    
  9. You can retrieve the value, entered by the user, using the below code.
    protected override void RenderWebPart(HtmlTextWriter output)        {        output.Write(this.text  );         }
  10. For expanding the custom category default we need to override the  function ‘GetToolParts’.Â
    public override ToolPart[] GetToolParts()
    {
    ToolPart[] toolpart = new ToolPart[3];
    CustomPropertyToolPart custom = new CustomPropertyToolPart();
    custom.Expand("Advanced Settings");
    WebPartToolPart Wptp = new WebPartToolPart();
    Wptp.FrameState = FrameState.Normal;
    Wptp.FrameType = FrameType.Default;
    toolpart[0] = Wptp;
    toolpart[1] = custom;
    return toolpart;
    }

The following properties can be added to costom controls in the tool part pane.

The custom property will be displayed automatically in the default property pane based on the property type string, bool, int or enum. The following table describes how each of these property types is displayed in the property pane.

In the coming articles we will see how to validate custom controls in tool part pane.

Download the sample source code here.

2 responses so far

Create a custom theme in MOSS

Mar 24 2010 Published by Radhika under MOSS 2007, SharePoint Design Customisation, Tips

Customising a sharepoint site is really a challenging job and there may be situations in which you might need to create a new theme. The simplest way is to create the new theme by taking a copy of the existng them. SharePoint theme folder has mainly 3 elements theme.inf, theme.css and images.

  1. Create a copy of any one of the theme folder in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\THEMES” and rename as “mytheme“. For example copy the folder named “SAMPLE” and rename it to mytheme.
  2. Rename the SAMPLE.INF file to MYTHEME.INF, remember all letters should be in upper case.
  3. Open MYTHEME.INF file in your favourite text editor and change the value of title as per your needs.
  4. Replace every word “SAMPLE” with “MYTHEME
  5. Change theme.css file to include your custom styles
  6. Save and close the editor
  7. Then open C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\SPTHEMES.XML in a text editor
  8. Add the follwing  lines under <spthemes> tag
  9. <Templates><TemplateID>Mytheme</TemplateID>
    <DisplayName>Mytheme</DisplayName>
    <Description>My new custom theme.</Description>
    <Thumbnail>images/home.gif</Thumbnail>
    <Preview>images/home.gif</Preview>
    </Templates>
    
  10. paste your home.gif in images folder.
  11. do IIS reset.

How to test your new theme

Got to site actions–>site setting –> look and feel–> you can see your custome theme there

No responses yet

Have a question about SharePoint? Ask the MVPs

Mar 12 2010 Published by Shoban under MOSS 2010, SharePoint Events

Do you have tough technical questions about SharePoint? Are you ready for some answers? Well we can help. Ask the talented and very knowledgable Microsoft Most Valuable Professionals.

The SharePoint MVPs are the same people you see in the technical community as authors, speakers, user group leaders and answerers in the MSDN forums. This is the first time we have brought these experts together as a collective group to answer your questions live! So please join us and bring on the questions. This chat will cover WSS, MOSS and the SharePoint 2010 beta.

Topics include:

  1. setup and administration
  2. design and development
  3. Q &A to follow

When:  March 15, 2010

Time:  9:00 am PDT

Where: MSDN Chat Room

Add this to your calendar

Join this Facebook Event

Source

2 responses so far