Home > Sharepoint Exam > Add document button

Add document button

December 31, 2011 6:04 pm Leave a comment Go to comments

In recent project that I worked on they did not like the link that appears underneath the document library and wanted to have a button that would do the same as the link and provide the following user interface for out of box Shared Documents Library

image

<View List="Lists/ProjectArtifactList" BaseViewID="1" WebPartZoneID="BottomColumnZone3" WebPartOrder="1" DefaultView="TRUE" ID="artifactListViewWebPart">
          <![CDATA[
            <webParts>
              <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
                <metaData>
                  <type

name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart,Microsoft.SharePoint,
Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"

/>
                  <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
                </metaData>
                <data>
                  <properties>
                    <property name="AllowConnect" type="bool">True</property>
                    <property name="ChromeType" type="chrometype">None</property>
                    <property name="AllowClose" type="bool">False</property>
                  </properties>
                </data>
              </webPart>
            </webParts>
          ]]>
        </View>

How to get the user interface and button linked?

<AllUsersWebPart WebPartZoneID="RightColumnZone" WebPartOrder="2">
         <![CDATA[
        <webParts>
       <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
         <metaData>
           <type name="AddDocumentToProject.AddDocumentWebPart, ProjectWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=50645fab795830a9" />
           <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
         </metaData>
         <data>
           <properties>
             <property name="Title" type="string">Add a Document</property>
             <property name="Description" type="string">Web Part to add Document to Project Button</property>
             <property name="ChromeType" type="chrometype">TitleOnly</property>
           </properties>
         </data>
       </webPart>
       </webParts>
       ]]>
       </AllUsersWebPart>

image

Code that would make the link between the document and upload:

Button btnRequest = new Button();
           //*future enhancement – put button text in resource file
           btnRequest.Text = "Add Document to Project";
           string listId = SPContext.Current.Web.Lists["ProjectArtifactList"].ID.ToString("B").ToUpperInvariant();
           btnRequest.OnClientClick = "javascript:NewItem2(event, ‘" + SPContext.Current.Web.ServerRelativeUrl + "/_layouts/Upload.aspx?List=" + listId + "&RootFolder=’);javascript:return false;";
           //btnRequest.PostBackUrl = string.Concat("javascript: MMAcceptPage(‘", SPContext.Current.Site.RootWeb.Url, "/SitePages/AcceptPage.aspx’)");
          
           //css class below is part of mm-base.css in community master page project
           this.Controls.Add(new LiteralControl("<div class=’mm-createproject’>"));
           this.Controls.Add(btnRequest);
           this.Controls.Add(new LiteralControl("</div>"));

This would provide the same user interface on click as below:

image

As you can see from the picture above we don’t have upload multiple files and other links that we didn’t need as it confused our users.

Advertisements
Categories: Sharepoint Exam Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: