SharePoint 2013 Development--Developing and deploying WebPart

Source: Internet
Author: User

??Blog Address: Http://blog.csdn.net/FoxDave

WebPart We do not elaborate, in the development of the app, custom property settings are passed through the URL query string of the app WebPart, which displays the remote content through an IFRAME. Needless to say, we started the actual operation.

Open Visual Studio, create a new SharePoint application project, name we are called Sharepointappparttest.

Refer to the previous article to complete the creation of the project. Right-click the SharePoint project node, select Add New Item, select the Client Web Part (host Web), name Clientwebparttest, click OK and leave the default finish add in the next dialog box.

US ?? you can see that the solution is generated as:

There is a Elements.xml element in the SharePoint project that describes the WebPart that we created, and a corresponding ASPX page was generated under the Pages folder in the managed Web application. Open the Elements.xml file to see the following default generated content:

<clientwebpart name= "Clientwebparttest" title= "clientwebparttest title" description= "Clientwebparttest description" Defaultwidth= "defaultheight=" >    <!--Content element identifies the location of the page that will be rendered within the client Web part         using patterns on the query string Propertyname_ references a Property         example: src= "~appweburl/pages/clientwebpart1.aspx? Property1=_property1_ "-    <content type=" html "src=" ~remoteappurl/pages/clientwebparttest.aspx?{ Standardtokens} "/>    <!--define attributes in the properties element.         Remember to place the attribute name on the SRC attribute of the Content element above. -    <Properties>    </Properties>  </ClientWebPart>

Let's add a few properties, under the Properties node, declaring the following four properties (string, int, bool, enum):

<property name= "Mystrprop" type= "string" requiresdesignerpermission= "true" defaultvalue= "string def Ault value "webcategory=" My Test Apps "Webdisplayname=" A property of type String. "       > </Property> <property name= "Myintprop" type= "int" requiresdesignerpermission= "true" Defaultvalue= "0" webcategory= "My Test Apps" Webdisplayname= "A property of type Integer." > </Property> <property name= "Myboolprop" Type= "boolean" requiresdesignerpermission= " True "Defaultvalue=" false "webcategory=" My Test Apps "Webdisplayname=" A property of type Boolean. " > </Property> <property name= "Myenumprop" type= "enum" requiresdesignerpermission= "Tru E "defaultvalue=" 1st "webcategory=" My Test Apps "Webdisplayname=" A property of type enum. " > <EnumItems> <enumitem webdisplayname= "first option" value= "1st"/>          <enumitem webdisplayname= "Second option" value= "2nd"/> <enumitem webdisplayname= "third option" Value= "3rd"/> </EnumItems> </Property>

are used in our testing, so the name is a bit arbitrary, the actual application please take meaningful names. After a property is created, how do I associate it with a WebPart? We need to modify the SRC attribute of the content node, and the modified node looks like this:

<content type= "html" src= "~remoteappurl/pages/clientwebparttest.aspx? {standardtokens}&amp;   />

In this way, the parameters of the APP WebPart are passed to the ASPX page through the URL's query string, and then we go to the ASPX page to process our defined parameters.

Open the Clientwebparttest.aspx page and add the following controls inside the empty div element:

<asp:label id= "Label1" runat= "Server" ></asp:Label>
<asp:literal id= "Literal1" runat= "Server" text= "Hello World from an app part! "></asp:Literal>

Open Background Code ClientWebPartTest.aspx.cs, add the following code to the Page_Load method to get the passed arguments:

var Intparam = request.querystring["Intprop"];            var strparam = request.querystring["Strprop"];            var Boolparam = request.querystring["Boolprop"];            var Enumparam = request.querystring["Enumprop"];            var editMode = request.querystring["EditMode"];            if ("true" = = EditMode) {Literal1.text = "The App is in edit mode"; } else {literal1.text = "Myintprop =" + Intparam + "<br>" + "M Ystrprop = "+ Strparam +" <br> "+" Myboolprop = "+ Boolparam +" <br> "+" Myenu            Mprop = "+ Enumparam; }
var spContext = SharePointContextProvider.Current.GetSharePointContext (Context); using (var clientcontext = Spcontext.createuserclientcontextforsphost ()) {Clientcontext.load (cl Ientcontext.web, Web = web.                Title);                Clientcontext.executequery (); This.            Label1.Text = "Site Title:" + clientContext.Web.Title + "<br>"; }

I added a previous csom to the code, and I wanted to use a simple combination to tell you that we can actually do a lot of things in it.

F5 build and deploy the app, after successful pop-up browser form:

Same thing, by default it jumps to the app's default page, we go back to our developer site, click Edit Page in the top right corner, select the Insert tab, click Application Parts.

Click the Add button to complete the action of adding a WebPart on the page.

Well, the WebPart already shows what we let it show.

We go back to the editing state, edit this webpart, and we can see the custom attributes we added. We modify the properties and save them appropriately.

The above is the general process of developing the app WebPart.

Another point to note is that because we are not publishing the app in the debug state, we need Visual Studio to be in debug mode for access testing. ??

SharePoint 2013 Development-Developing and deploying WebPart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.