Showing posts with label Visual Studio 2010. Show all posts
Showing posts with label Visual Studio 2010. Show all posts

Friday, August 24, 2012

Programmatically creating Wiki Pages


The Windows SharePoint Services Object Model provides some methods for Wiki Pages Library Programmability. Using these methods, we can create new Pages in Wiki Pages Library and set a default page in the Wiki Pages Library. The following snippet is the sample for creating Wiki Pages in a Wiki Pages Library.
using (SPSite site = new SPSite("http://sharepoint"))
{
 SPWeb currentWeb= site.RootWeb;
 SPList spList = currentWeb.Lists["Site Pages"];
  SPFolder wikiRootFolder = spList.RootFolder;
 if (spList != null) {
 try {
  SPFile wikiPage = wikiRootFolder.Files.Add(String.Format("{0}/{1}", wikiRootFolder, "WikiPage.aspx"),                                           SPTemplateFileType.WikiPage);
   SPListItem wikiItem = wikiPage.Item;
   wikiItem[SPBuiltInFieldId.WikiField] = "Wiki Page Content "; 
 wikiItem.UpdateOverwriteVersion();
 wikiRootFolder.Update();
 }
}
}
For getting Wiki Page information, there are some suggestions from Waldek Mastykarz. I would Thank him for his great post. Please refer to the following link: http://blog.mastykarz.nl/programmatically-creating-wiki-pages/

Error occurred in deployment step 'Activate Features': Object reference not set to an instance of an object

Error occurred in deployment step 'Activate Features': Object reference not set to an instance of an object. This is a common Error that every SharePoint developer will do.

We cannot use SPContext.Current.Web in feature receivers. They can be run by the timer service or powershell which does not have access to the SPContext.

So We can create instances for out SPsite and SPWeb as mentioned below.

using (SPSite site = (SPSite)properties.Feature.Parent)
{
   using (SPWeb web = site.OpenWeb())
   {
            Our code
            ---------------------
            ---------------------
---------------------
                       
   }
}

Monday, July 23, 2012

Sys.Webforms.PageRequestManagerServerErrorException ...:500

Ajax Error: Sys.Webforms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was : 500

This issue sometimes occurs when you have a control registered as an AsyncPostbackTrigger in multiple update panels.


Resolution: To solve this issue we need to add below web.config entry to WFS the servers.

<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="100000" />
</appSettings>

<system.web.extensions> <scripting> <scriptResourceHandler enableCompression="false" enableCaching="true"/> </scripting> </system.web.extensions>


Friday, June 22, 2012

JSON Enabled WCF Service using VS2010


The advantages of using JSON enabled WCF service is that the data is communicated in plain text like stream, it does not require any data/message parsing. For exposing a WCF service as JSON enabled WCF service, we need to apply the [WebGet] attribute on the method of the ServiceContract with ResponseFormat as JSON. The binding used here is WebHttpBinding which is also used for REST enable WCF services. While exposing WCF as JSON enable service, the EndPointBehavior for the WCF service is WebHttp which generates JSON response from the WCF service.

Step 1: Open VS2010 and create a new WCF service application, name it as ‘WCF_JSONService’. Open Iservice1.cs and add the following ServiceContract, OperationContract, DataContract. Apply WebGetAttribute on the OperationContract as shown below:



Step 2: Implement the above IService1.cs in the service class:



Step 3: Write the Web.Config file as shown below with ‘WebHttpBinding’ and the ‘EndpointBehavior’:

Step 4: Right click on the WCF service and select properties, select ‘Web’ tab and write the following Url in the ‘Use Local IIS Web Server’:

By using this approach, the WCF service is published on the web Server

Step 5: Open IIS and navigate to the Virtual Directory ‘WCF_JSONService’ created above. Right click on the Service1.Svc and the following result will be displayed:



Now change the url as shown below and hit Enter, the JSON file data will be downloaded as shown below: http://localhost:8081/WCF_JSONService/Service1.svc/Products



Save the file on disc and view it. The data in the response will be similar to the following:

For demo purposes, I am displaying the Data in a notepad. You can always consume it in any client application like Silverlight, as demonstrated here . The advantage of using JSON over REST is, since REST is XML messaging format, it requires parsing. However this is not required in JSON.