Thursday, April 19, 2012

Create and apply branding to a SharePoint site














  • Web Content Management and Branding
  • Pages in SharePoint 2010
  • Master Pages
  • SPWeb.MasterUrl
  • SPWeb.ThemedCssFolderUrl
  • SPWeb.AlternateCssUrl
  • ScriptLink
  • CSS Link
  • CSS Registration

  • Web Content Managment and Branding :-  Web content managment and branding defines the layouts appearence and organize your data in a smart way where branding refer to customize your master pages creates site columns, content type, page layout adding css and links and web conent management refer the handling the data of variouse sources from inbuilt features of sharepoint. In this section we will work on the following parts of sharepoint 2010

     

    How to: Customize Navigation in SharePoint Server 2010 (ECM)

    Cutomize Navigation In Sharepoint Server : the Navigation is the site centric in sharepoint it means every web in the site collection can have it's own navigation style. Using the navigation API's we can work on the horizontal and verticle menus. The menus can be created on the fly as well as static menues are available. you have the site map provider and you can also create customize provider.

    Working on the Horizontal and verticle Menu's :- The older asp.net menus used in the horizontal and verticle menus menus are binding with the datasource(which is portalSiteMAPDATASTORE) this also include the orientation, level etc
    <SharePoint:AspMenu ID="GlobalNav" Runat="server"
      DataSourceID="GlobalNavDataSource"
      Orientation="Horizontal"
      StaticDisplayLevels="1"
      MaximumDynamicDisplayLevels="1" />
    
    PortalSiteMapProvider object provide the site hirarachy(Navigation structure) and determine the reletions between nodes. on the other hand PortalSiteMapDataStore object maps the data from PortalSiteMapProvider and filter them and determine what data should be viewable to the user.

    PortalSiteMapProvider :
    <PublishingNavigation:PortalSiteMapDataSource ID="GlobalNavDataSource"
      Runat="server"
      SiteMapProvider="CombinedNavSiteMapProvider"
      ShowStartingNode="false"
      StartFromCurrentNode="true"
      StartingNodeOffset="0"
      TrimNonCurrentTypes="Heading"
      TreatStartingNodeAsCurrent="true" />
    
    PortalSiteMapDataStore:
    <add name="CombinedNavSiteMapProvider" description="MOSS 2007 provider for Combined navigation"
       Type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider"
       NavigationType="Combined" EncodeOutput="true">
    <add name="CurrentNavSiteMapProvider" description="MOSS 2007 provider for Current navigation"
       Type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider"
       NavigationType="Current" EncodeOutput="true" />

    Customizing Web Display Controls (Menu, TreeView, and SiteMapPath)

    You can always customize the menus, treeview and change the apearence of your existing site using the controls Menus(System.UI.WebControls.TreeView,System.UI.WebControls.Menu), the menu controls can also be branding from css.
    Implementing Site Map Provider.
    To implement your own site map provider, you can derive a custom provider class from any of the default site map providers. By inhering the sitemapprovider class you will be able to overriden the method GetChildNodes which will return you SiteMapNodeCollection(Node collection) and it can be bind to the navigations controls
    public class CustomNavProviderWithList : PortalSiteMapProvider

    How to: Extend the Navigation Provider in SharePoint Server 2010 (ECM)

    You can extend the navigation provider in Microsoft SharePoint Server 2010 by deriving a custom provider class from any of the default site map providers.

    Step 1 :
    Create a Microsoft Visual C# class library project with the following code, add the required references, and then build the project.
    1. using System;
      using System.Collections.Generic;
      using System.Text;
      using Microsoft.SharePoint.Publishing;
      using Microsoft.SharePoint.Publishing.Navigation;
      using System.Web;
      using System.Web.UI.WebControls;
      using System.Configuration;

      namespace MyCustomNav
      {
      public class Navigation: PortalSiteMapProvider
      {
      public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode
      node)
      {
      PortalSiteMapNode pNode = node as PortalSiteMapNode;
      if (pNode != null)
      {
      if (pNode.Type == NodeTypes.Area)
      {
      SiteMapNodeCollection nodeColl = base.GetChildNodes(pNode);
      SiteMapNode childNode = new SiteMapNode(this,
      "<http://www.microsoft.com>", "<http://www.microsoft.com>", "Microsoft");

      SiteMapNode childNode1 = new SiteMapNode(this,
      "<http://support.microsoft.com>", "<http://support.microsoft.com>", "Support");

      nodeColl.Add(childNode);

      SiteMapNodeCollection test = new SiteMapNodeCollection();
      test.Add(childNode1);
      childNode.ChildNodes = test;

      return nodeColl;
      }
      else
      return base.GetChildNodes(pNode);
      }
      else
      return new SiteMapNodeCollection();
      }
      }
      }
    1. Copy the .dll file that you created in step 1 into the SharePoint Server 2010 virtual directory’s bin folder.
    2. Create the following entry in the web.config file for the Web application, and then set the trust level to Full.
    3. Create a custom master page, and then add the following code under the top navigation’s ContentPlaceHolder element.
    <SharePoint:AspMenu
    ID="TopNavigationMenu"
      Runat="server"
      DataSourceID="topSiteMap1"
      EnableViewState="false"
      AccessKey="<%$Resources:wss,navigation_accesskey%>"
      Orientation="Horizontal"
      StaticDisplayLevels="1"
      MaximumDynamicDisplayLevels="3"
      DynamicHorizontalOffset="0"
      StaticPopoutImageUrl="/_layouts/images/menudark.gif"
      StaticPopoutImageTextFormatString=""
      DynamicHoverStyle-BackColor="#CBE3F0"
      SkipLinkText=""
      StaticSubMenuIndent="0"
      CssClass="ms-topNavContainer">
    <StaticMenuStyle/>
    <StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
    <StaticSelectedStyle CssClass="ms-topnavselected" />
    <StaticHoverStyle CssClass="ms-topNavHover" />
    <DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE"
      BorderWidth="1px"/>
    <DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
    <DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
    <DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
    </SharePoint:AspMenu>
    <asp:SiteMapDataSource
      ShowStartingNode="False"
      SiteMapProvider="MyCustomNavigationProvider"
      id="topSiteMap1"
      runat="server"
      StartFromCurrentNode="true"/>

    4.  Reset Microsoft Internet Information Server (IIS). Your SharePoint Server site should now show the updated navigation from the extended navigation provider.

    Master Pages
    Master pages provide the consist and standard look to the site. Master pages use the content page and togeter render as a single page. Master pages defines the common area for all the pages such as branding navigation header footer and left and right area.
    There has been significate changes in the v4.Master as it embaded the ribbon interface and many controls of navigation such as menus etc have been placed in the Ribbon area So if you does not include ribbon interface you will lose some functionality.

    Upgrading an Existing Master Page to the SharePoint Foundation Master Page

    Controls on the Server Ribbon : Server Ribbon automatically implement the following controls in the ribbon So if you are planning to upgrade your master page to 2010, you will have to remove all the components which already exists in Ribbon reason is when you added the Ribbon interface controls automatically included. So from the existing master page following controls needs to be removed
    • Publishing Console - <PublishingConsole:Console>
    • Site Actions Menu - <PublishingSiteAction:SiteActionMenu>
    • Sign-in and Log-in Control.
    Add Content Placeholders : Make sure all the content place holder are updated with the sharepoint 2010 version, If you want to see the compatible placeholder go to the below link and verify your newly added master pagehttp://msdn.microsoft.com/en-us/library/ee539981.aspx
    Add your server Ribbon control : To add server ribbon control open your custom master file and put the below code inside <form> tag
    <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">
      <div id="s4-ribboncont">
        <SharePoint:SPRibbon
         runat="server"
         PlaceholderElementId="RibbonContainer"
         CssFile="">
          <SharePoint:SPRibbonPeripheralContent
      runat="server"
      Location="TabRowLeft"
      CssClass="ms-siteactionscontainer s4-notdlg">
         <%-- Insert the Site Actions Menu Here --%>
         </SharePoint:SPRibbonPeripheralContent>

         <%-- Insert the Global Navigation Here --%>
         <SharePoint:SPRibbonPeripheralContent
           runat="server"
           Location="TabRowRight"
           ID="RibbonTabRowRight"
           CssClass="s4-trc-container s4-notdlg">
         <%-- Insert the Top-Right Corner Controls Here --%>
         </SharePoint:SPRibbonPeripheralContent>

        </SharePoint:SPRibbon>
      </div>
      <div id="notificationArea" class="s4-noti">
        <%-- Notifications will appear in this div element. --%>
      </div>
      <asp:ContentPlaceHolder ID="SPNavigation" runat="server">
        <SharePoint:DelegateControl runat="server" ControlId="PublishingConsole">
        </SharePoint:DelegateControl>
      </asp:ContentPlaceHolder>
      <div id="WebPartAdderUpdatePanelContainer">
        <asp:UpdatePanel
         ID="WebPartAdderUpdatePanel"
         UpdateMode="Conditional"
         ChildrenAsTriggers="false"
         runat="server">
            <ContentTemplate>
              <WebPartPages:WebPartAdder ID="WebPartAdder" runat="server" />
            </ContentTemplate>
            <Triggers>
              <asp:PostBackTrigger ControlID="WebPartAdder" />
            </Triggers>
        </asp:UpdatePanel>
      </div>
    </div>
    Save the file

    To maintain the position of the Server ribbon while scrolling

    <div id="s4-workspace">
      <div id="s4-bodyContainer">
        Content
      </div>
    </div>
    Move the title area of your site into a div element with the following ID.
    <div id="s4-titlerow"> Title Area </div>

    Update the body tag and Cascading Style Sheet (CSS) rule to not scroll. The body tag and rule would look similar to the following.
    <body scroll="no" ...>
      Body Content
    </body>
    body { overflow: hidden; ... }
    Add Controls to the Master Page

    • The SPPageManager control manages communications on the page. This control takes care of routing commands to and from the Server ribbon, toolbars, and other controls on the page.
    • The ScriptManager object is a Microsoft ASP.NET control that is used to manage all of the ECMAScript (JavaScript, JScript) on the page. Due to the extensive use of JavaScript in SharePoint Foundation, you must have an instance of the ScriptManager on the page.
    • The ScriptLink control is necessary to handle adding references to JavaScript on the page. This control renders a link to the JavaScript on the page.

    <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true" />
    <SharePoint:SPPageManager runat="server" />
    <SharePoint:ScriptLink defer= "true" runat="server"/>

    Also refer this link if you have face any kind of IE problem
    http://blog.drisgill.com/2009/03/problems-with-ie8-standards-mode.html

    Customizing Ribbon Positioning in SharePoint 2010 Master Pageshttp://blogs.msdn.com/sharepoint/archive/2010/04/06/customizing-ribbon-positioning-in-sharepoint-2010-master-pages.aspx


    SharePoint Dialog Auto-Sizing and Master Page Customizationhttp://blogs.msdn.com/sharepoint/default.aspx?p=2


    How to: Customize Styles in SharePoint Server 2010 (ECM)

    In many cases a designer wants to customize the style sheet of content pages. the HTML editor provide such kind of funtionality from that you can add your custom css and apply the css to the fields controls as well, you can replace ms-rteCustom-XXXX where xxxx your unique class name

    You can specify a unique CSS class name prefix for each publishing HTML field control so that you can present different custom styles for different sections of the page.
    In the page layout where the RichHTMLField control is specified, you can override the PrefixStyleSheet property. For example, if you specify the following code, the HTML editor looks for CSS classes with the PageContentStyleCustom prefix in associated CSS syntax:
    <PublishingWebControls:RichHtmlField id="Content" FieldName="PublishingPageContent" runat="server" PrefixStyleSheet-"PageContentStyle"/>

    By default, the HTML editor presents the default set of styles, but a page layout designer may replace the default set by adding references to style sheets in the page layout. If the HTML editor detects new Cascading Style Sheet (CSS) classes whose names have the prefix ms-rteCustom-XXXX, where XXXX is the display name of the classes unique to the page, it displays the new set of custom styles instead of the default set.

    Customizing Styles of Summary Links, Table of Contents, and Content By Query Web Parts

    The summary Links and Content query web part can be used to create the author links and you can always changes how the items should apear. You can also change the style of Table of content and content query web part both can be data drivan web part and retrieve data from sharepoint site contents. To change the styles follow the following points
    •  Go to the viewallconent
    • Go to the Style library
    • Go to xml style sheet
    ContentQueryMain.xsl"Application" XSL style sheetContent Query
    Header.xslGroup headers for Content Query and Summary Links, title headers for Table of ContentsContent Query, Summary Links, Table of Contents
    ItemStyle.xslContent Query and Summary Link item stylesContent Query, Summary Links
    LevelStyle.xslTable of Contents level styles, which includes the site and its pagesTable of Contents
    SummaryLinkMain.xsl"Application" XSL for Summary LinksSummary Links
    TableOfContentsMain.xsl"Application" XSL for Table of ContentsTable of Contents

    To create a new style

    1. Repeat steps 1 through 4 of the previous procedure to navigate to the ItemStyle.xsl file.
    2. Open the ItemStyle.xsl file and add the following code.
      <xsl:template name="MyCustomStyle" match="Row[@Style='MyCustomStyle']" mode="itemstyle">
      </xsl:template>
      3. Add template name, variables, parameter information, and other details between the open and close tags in the ItemStyle.xsl file, as needed.
      4. Add HTML and the appropriate XSL statements to display the variables appropriately in the Web Part. 

    How to: Customize the SharePoint Content By Query Web Part by Using Custom Properties (ECM)

    Content query web parts provide the facilility to retrieve the data from variouse sources and display it according to user. Content query web part provide several mehtods and properties and methods to

    Properties that modify UI and behavior
    CommonViewFields
    Requests additional fields, which is necessary because the Content By Query Web Part does not return all fields for all items automatically. You must request fields to render in an XSLT transformation.
    WebsOverride
    ListsOverride
    ViewFieldsOverride
    DataColumnRenames

    Approaches to Customizing a Content Query Web Part
    1. Log on to your Web site.
    2. On the Site Actions menu, click Edit Page.
    3. Find the Content By Query Web Part on the page, and then on the Web Part's edit menu, click Export.
    4. Save the .webpart file.
    5. Rename the .webpart file, and then use a text editor or SharePoint Designer 2010 to open the renamed file.
    6. Add or modify properties and property values, and then save your changes.
    7. On the Page menu, point to Add Web Parts, and then click Browse.
    8. Select the Web Part to import from the Web Part List, and then click OK.
    9. Drag the Web Part to a Web Part zone on the page.

    QueryOverride, ListsOverride, WebsOverride, and ViewFieldsOverride Properties

    Each override property—QueryOverride, ListsOverride, WebsOverride, and ViewFieldsOverride—overrides a default Content By Query Web Part behavior. To override a behavior, construct a CAML query that defines the conditions you want to set.

    How to: Customize XSL for the SharePoint Content By Query Web Part (ECM)

    There are three style sheet to present the data in content By query web part. you can use the style sheet according to your design.
    ContentQueryMain.xsl  
    \Style Library\XSL Style Sheets\ContentQueryMain.xsl








  • Contains logic that generates the appropriate calls to the Header and Item templates for each item.
  • Contains functions that help designers modify the Item and Header XSLT transforms.
  • Receives all the content, parses it, and sends appropriate pieces to the ItemStyle and Header templates.

  • ItemStyle.xsl
    \Style Library\XSL Style Sheets\ItemStyle.xsl
    Contains templates that define how to display an item. These templates receive and process one row of data at a time, ensuring that the style and data in the item rows is consistent.

    Header.xsl
    \Style Library\XSL Style Sheets\Header.xsl
    Contains templates that define how to display a header and ensure the consistency of group headers.
    Templates specified in Header.xsl receive the next item row to process, usually the first row in a group unless there are multiple columns. If there are multiple columns, the templates receive the first row of the column.

    How to: Customize the SharePoint HTML Editor Field Control (ECM)

    You can use the HTML Editor field control to insert HTML content into a publishing page. Page templates that include a Publishing HTML column type also include the HTML Editor field control. This editor has special capabilities, such as customized styles, editing constraints, reusable content support, a spelling checker, and use of asset pickers to select documents and images to insert into a page’s content. This topic describes how to modify some features and attributes of the HTML Editor field control.

    Predefined Table Formats

    The HTML editor includes a set of predefined table formats, but it can be customized to fit the styling of an individual page


    Exercise tasks which needed to complete
    * Edit a existing 2007 master page to 2010 master page
    * Create some good looking readymade master pages in
    sharepoint 2010
    * Created menus and navigation baars for sharepoint 2010
    * Created sitemapdatasource and SiteMapDataStore clear the
    concept
    * create some readymade content by query web part
    * Edit HTML field editor.


    SPWeb.MasterPageURL :

    You can set the master page url from the object model. gets or sets the master page url.
    spweb.masterurl = "/_catalog/masterpage/v4.master";
    spweb.custommasterurl = "/_catalog/masterpage/v4.master";
    spweb.update();

    SPWeb.ThemsCSSfolderURL :

    Gets or sets the URL to the folder that contains the cascading style sheets (CSS) file that is used in the theme for the website

    ScriptLink Class

    Provideds the properties to register the script on the page, so that page they can be requested when page is rendered.
    Represents a cascading style sheet (CSS) file registration. CssLink reads this registration to insert a LINK element into the resulting HTML page and apply the external style sheet(s) defined by the registration.
    Inserts a LINK element into the resulting HTML page and applies an external style sheet(s) defined by CssRegistration.



    Customize navigation programmatically




  • How to: Customize Navigation
  • Customizing Navigation Controls and Providers
  • Customizing Site Navigation


  • Website Navigation

    Certain elements of the Microsoft SharePoint Foundation user interface are designed to help users navigate to content within a website or site collection. You can customize these navigational elements by adjusting site settings through the user interface, by using Microsoft SharePoint Designer 2010 to create custom master or content pages, or by writing code that accesses the SharePoint Foundation object model.



    Navigation Controls

    • Breadcrumb
    • Top link bar
    • Quick Launch
    • Tree view
    BreadCrump : Bread crump provide you the exect location where you are, it is places just right from the site action menu with a folder icon with up row once you clicked the icon you can see the hirarchy where you are now.Breadcrump uses popout control, popout controls uses two main controls one is lable and other is Listsitemappath which uses SPSitemapprovider and SPContentMapProvider

    Top link bar : -

    top link baar represet the data into the tab, when you create a site only home tab rendred in the toplink bar. top link baar uses aspmenu with the horizontal orientation it also uses the SiteMapDataSource,TopNavigationDataSource and inside the content placeholder PlaceHolderHorizontalNav so it can be also overrides on the other sharepoint pages.
    SPNavigationNode toplinkbar = web.Navigation.GetNodeById(1002);
                        if (toplinkbar != null)
                        {
                            foreach (SPNavigationNode node in toplinkbar.Children)
                            {
                                Console.Write("| {0} ", node.Title);
                            }
                            Console.WriteLine("|");
                        }

    Quick Launch :
    Quick Launch is a menu of links that can appear on the left side of pages in a website. The menu is intended for navigation within a site and usually has links to lists and document libraries and other site content. It can also include links to external content.
    Site owners can enable or hide the Quick Launch menu by accessing the administrative user interface on the Site Actions menu. Developers can do the same thing by writing code. For more information, see How to: Display or Hide Quick Launch.
    In v4.master, the markup that defines the Quick Launch menu is nested inside a ContentPlaceHolder control (ID="PlaceHolderLeftNavBar") that also contains markup for the tree view control
    <SharePoint:AspMenu 
        id="V4QuickLaunchMenu" 
        runat="server" 
        EnableViewState="false" 
        DataSourceId="QuickLaunchSiteMap" 
        UseSimpleRendering="true" 
        UseSeparateCss="false" 
        Orientation="Vertical" 
        StaticDisplayLevels="2" 
        MaximumDynamicDisplayLevels="0" 
        SkipLinkText="" 
        CssClass="s4-ql" />
    SPNavigationNode quicklaunch = web.Navigation.GetNodeById(1025);
                        if (quicklaunch != null)
                        {
                            foreach (SPNavigationNode heading in quicklaunch.Children)
                            {
                                PrintNode(heading);
                                Console.WriteLine(new String('-', 10));
                            }
                        }
    
    Tree View


    3. Create hidden fields to store the information you will need to modify the url.
        <input type="hidden" id="listId" runat="server" />
        <input type="hidden" id="itemId" runat="server" />
        <input type="hidden" id="sourceUrl" runat="server" />
        <input type="hidden" id="webUrl" runat="server" />
    4. Setup the hidden fields in your Page_Load event.
    listId.Value = list.ID.ToString();
            itemId.Value = listItem.ID.ToString();
            sourceUrl.Value = list.DefaultViewUrl;
            webUrl.Value = web.Url;
    5. Use the hidden fields in the javascript function you wrote above. 
    <script type="text/javascript">
        function openDialog() 
        {
            var options = 
            {
         url:  $("#<%= webUrl.ClientID %>").val()+ "/_layouts/AttachFile.aspx?ListId=" + $("#<%= listId.ClientID 
                         %>").val() + "&ItemId=" + $("#<%= itemId.ClientID %>").val() + "&Source=" + $("#<%= 
                         sourceUrl.ClientID %>").val(),
         width: 800,
         height: 600,
         title: "Attach File",
            };
     SP.UI.ModalDialog.showModalDialog(options);
         }
    </script> 
    
    

    The tree view navigational element is intended to display a hierarchical view of all site content. By default, the tree view is disabled. When it is enabled, it appears in the left navigational area of the page. If Quick Launch is enabled, the tree view appears below it.
    An administrator for the website can enable the tree view by going to the Tree View page in the administrative user interface. To view the Tree View page, click Site Actions, and then click Site Settings. Under Look and Feel, click Tree view.
    You can enable the tree view in code by setting the SPWeb.TreeViewEnabled property to true.
    Like Quick Launch, the tree view has two versions. In v4.master, both versions are rendered by an SPTreeView control nested inside an SPRememberScroll control. The SPTreeView control gets its data from an instance of the SPHierarchyDataSourceControl class

    Module 10: Creating Dialogs and Ribbon Controls for SharePoint 2010


    How to Use Modal Dialog in Sharepoint 2010

    Posted on January 21, 2011 by princess
    Modal dialogs are really fun to work with but can be frustrating to implement if you don’t know what’s required to work with them. If you have a Java background you will be amazed with how SharePoint deals with modal dialogs. The concept is almost the same but you need a slightly different approach to implement it.
    Modal dialogs in SharePoint 2010 use the client library SP.UI.ModalDialog and showModalDialog. We can do the following within the context of a page without leaving the page:
    • Add and Edit metadata
    • Perform administrative task
    • Attach documents/files
    The following step-by-step instructions show you how to implement a modal dialog in your server side pages:
    1. Create a hyperlink that will be responsible for triggering your modal. Set the onclick attribute as follows:
    <a href="#" onclick="javascript:openDialog(); return false;">Open Attach File</a>
     
    2. Implement the openDialog function in javascript. 
    <script type="text/javascript">
        function openDialog() 
        {
            var options = 
            {
         url: http://server/_layouts/AttachFile.aspx?ListId={0F42F104-538C-4F3C-8098-0DD93C8CD779}&ItemId=246&Source=http%3A%2F%2Fdeadmines%2Fsites%2Fhorizon%2FLists%2FYear%2520End%2FMy%2520Inbox%2520%2520All%2520lists.aspx,
         width: 800,
         height: 600,
         title: "Attach File",
            };
     SP.UI.ModalDialog.showModalDialog(options);
        }
    </script>
     
    To be more dynamic…Hard coding the url is not recommended because it is really hard to maintain. There are lots of ways to make your code dynamic and this is only one of them. We could have also leveraged the url query strings that contain most of this information.
    3.
    1. Create hidden fields to store the information you will need to modify the url.
    <input type="hidden" id="listId" runat="server" />
        <input type="hidden" id="itemId" runat="server" />
        <input type="hidden" id="sourceUrl" runat="server" />
        <input type="hidden" id="webUrl" runat="server" /

    Setup the hidden fields in your Page_Load event.
    listId.Value = list.ID.ToString();
            itemId.Value = listItem.ID.ToString();
            sourceUrl.Value = list.DefaultViewUrl;
            webUrl.Value = web.Url;

    Use the hidden fields in the javascript function you wrote above.
    <script type="text/javascript">
        function openDialog() 
        {
            var options = 
            {
         url:  $("#<%= webUrl.ClientID %>").val()+ "/_layouts/AttachFile.aspx?ListId=" + $("#<%= listId.ClientID 
                         %>").val() + "&ItemId=" + $("#<%= itemId.ClientID %>").val() + "&Source=" + $("#<%= 
                         sourceUrl.ClientID %>").val(),
         width: 800,
         height: 600,
         title: "Attach File",
            };
     SP.UI.ModalDialog.showModalDialog(options);
         }
    </script>

    1 comment: