DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Archive for the ‘C#’ Category

Asccess Denied when accessing Webpart

Posted by PANVEGA on September 8, 2009

In various cases while developing custom web parts or controls for SharePoint we have to use the SPSecurity.RunWithElevatedPrivileges construct to execute some part of the code which needs elevated permissions or which cannot be run with the current user permissions. For example, updating a SPWeb object or SPList object needs elevated permissions.

If you are getting an unauhtorized access exception even after using this block then the reason could be as follows: Read the rest of this entry »


Posted in C#, DotNet, MOSS, Object Model | Tagged: , , , | Leave a Comment »

Accessing webparts in a page using the SP Object Model

Posted by PANVEGA on September 8, 2009

The SPLimitedWebPartManager provides a limited set of Web Part operations that can be performed in the SP object model. It can be accessed by adding the microsoft.sharepoint.dll rference to your class.

In a recent project I had to can the view of some ListViewWebparts in a normal SP Page. The best thing therefore is using the SPLimitedWebPartManager.

Any SharePoint page that includes Web Parts must have an instance of the SPWebPartManager on the page to manage Web Parts. This object tracks which zones each Web Part is in, connection information related to Web Parts, personalization, and page edit mode.” Read the rest of this entry »

Posted in C#, MOSS, Object Model | Tagged: , , | Leave a Comment »

Custom SharePoint Page Counter

Posted by PANVEGA on September 7, 2009

In this post I show you how easy it is to develope a custom Page Counter Webpart in Visual Studio.

In one of my older post I explaid how to add Counter Web Component to your page by using the SP Designer. However this approach has some disadvantages.

Steps to do:

  1. Create a new Custom Field for instance PageCounter
  2. Add this custom field to your Page ContentTypes by using a FeatureReceiver Class
  3. Create a Webpart project
  4. Access the Pages List and parse all pages.
  5. increment the custom PageCounter filed
  6. Incremt just in Publish Level Mode
  7. do a item and list update Read the rest of this entry »

Posted in C#, MOSS, WebParts | Tagged: , , | Leave a Comment »

Add a Custom Application.master by using the HttpHandler

Posted by PANVEGA on September 3, 2009

In this post I am going to show you how to apply a custom Application.master to your ShareP0int application by using the IHttpModule. My approach was to create an “HttpHandler” that simply would override the “Page_PreInit” method and change the master page.

Of course you have to create a solution in order to deploy your CustomApplication.master to the 12 Hive folder (e.g. LAYOUTS\CustomMaster\CustomApplication.master). The path to your master page in your 12 Hive and  in the code below should be correct.

page.MasterPageFile = “/_layouts/CustomMaster/CustomApplication.master”;

After you activated the feature and you want to load a page setting for instance, Sharepoint should now apply your custom master. Read the rest of this entry »

Posted in C#, DotNet, MasterPage, MOSS, Object Model | Tagged: , , , | Leave a Comment »

Using SPWebConfigModification within a Feature Receiver

Posted by PANVEGA on September 2, 2009

Sometimes when developing moduls for SharePoint you have to register these modules in your application web.config. You can easily do this by using the SPWebConfigModification class in combination with a feature receiver.

This class holds modifications that are made to the web.config.

Quite often I have to make some changes in the web.config files of the web applications where my solutions are to be deployed. Manifest.xml files of Sharepoint Solutions helps us with this task providing us with some easy ways to alter the web.config files, unfortunately, we are limited at registering safe controls and alter security policies which sometimes is not enough. Read the rest of this entry »

Posted in C#, Deployment, MasterPage, MOSS, Object Model | Tagged: , , , , | 1 Comment »

Failed to load viewstate Error

Posted by PANVEGA on August 27, 2009

When I developed a Custom Webpart I had to build some dynamic added ASP Control (DropDownList etc.) during and after postback. Then I received the follwing error message during the Webpart was changing the Controls.

Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.


For example, if I dynamically add a textbox to a page, that textbox MUST exist before the viewstate for the page is loaded after a postback. This is because the when the page attempts to load viewstate, the control hierarchy must match the control hierarchy that existed when viewstate was originally created. Read the rest of this entry »

Posted in C#, MOSS, WebServices | Tagged: , , | Leave a Comment »

Custom SharePoint TreeView Navigation with CodeBehind

Posted by PANVEGA on July 12, 2009

In this short post I gonna explain how easy it is to customize your tree view navigation. In one of my prevois post I explaind how to customize your QuickLaunch Left Navigation in your MasterPages ASP:Menu properties. However the confiuration at this point was limited. I needed a dynamic 3 Level with an automatic expaned and collapse menu.

Read my previous post first:

You can solve this problem by using asp:TreeView control: Read the rest of this entry »

Posted in C#, DotNet, MasterPage, MOSS | Tagged: , , , | 3 Comments »

Custom Silverlight Navigation with the SP PortalSiteMapProvider

Posted by PANVEGA on June 2, 2009

In this post I wanna explain in a few steps how to develope a custom Silverlight Navitgation for SharePoint publishing sites (Source Silverlight Blueprints on CodePlex)

SharePoint and Silverlight Blueprints on CodePlex were uploaded to include two more Silverlight RTM samples: custom navigation in SharePoint and the colleague viewer. These blueprints provide samples for you to build and explore using Silverlight as an alternate way to develop and integrate powerful user experiences within SharePoint and add rich Internet application functionality to your SharePoint sites. Included in the overall set of samples are a Hello World sample, a Slider sample, and the recently added Custom Navigation and Colleague Viewer samples added

Read the rest of this entry »

Posted in ASP.NET, C#, DotNet, MasterPage, MOSS, Silverlight | Tagged: , , , , , | 1 Comment »

Lists.asmx/GetListItems Accessing the XmlDocument by using the Namespace

Posted by PANVEGA on March 20, 2009

In this short post I am gonna show you how easy it is accessing the List Item values from the GetListItems method of the Lists.asmx Webservice.

  1. Call your GetListItem method
  2. store the XML in a XmlDocument
  3. You have to build a new XmlNamespaceManage
  4. Add the Namespace properties
  5. In this example I wanna access the XmlNode with the first List Item ID

Read the rest of this entry »

Posted in C#, DotNet, MOSS, WebServices | Tagged: , , , | Leave a Comment »

Query List Items from Lists.asmx Webservice GetListItems

Posted by PANVEGA on March 20, 2009

I created an application where I can retreive a Field ID from a Custon List Item with the Query GetListItem options.

A Query element containing the query that determines which records are returned and in what order, and that can be assigned to a System.Xml.XmlNode object, as in the following example.

  1. Call the GetListItem method
  2. Below you see the parameters from this method
  3. Create a new XmlNode call it “Query”
  4. Create a XmlElement call it “QueryOptions”
  5. Add you custom Query parameters you want
  6. I wanted to query the Item with the ID from the Application Read the rest of this entry »

Posted in C#, DotNet, MOSS, WebServices | Tagged: , , , | 2 Comments »

How to manipulate InfoPath with CodeBehind

Posted by PANVEGA on February 16, 2009

I wonna show you how easy it is to manipulate the InfoPath Formular in C# Codebehind. The compiled DLL becomes part of the InfoPath form template (XSN) file.

1. First you have to install the VSTA tools for Visual Studio.

With the familiar Visual Studio development environment, VSTA enables Visual Basic and Visual C# developers to easily build managed customizations for both COM and .NET applications. The VSTA SDK includes integration tools, samples, and documentation to help you get started with VSTA.

Download Visual Studio Tools for Applications (VSTA)  here

2. Then create in InfoPath a new Formular with some for instance textboxes and Submit buttons. Under Tool–> Programming –>Microsoft Visual StudioTools… you will automatically redirected to the VS CodeBehind InfoPath Project.

3. In addition the Tool deploys a dll in your XSN file when building the project. Read the rest of this entry »

Posted in C#, DotNet, InfoPath, MOSS, XPath | Tagged: , , , , | 2 Comments »

Using ASP in JavaScript for URL Encoding in SharePoint fields

Posted by PANVEGA on February 3, 2009

In this post I want to show you how to rebuild the standard MyLinks –> Add to My Links for a custom MyLinks Control in Visual Studio and using ASP in JavaScript.

Active Server Pages exposes an object called ServerVariables, which is part of the Request object. This ServerVariables object allows the programmer to see many environment variables. You can use the ServerVariables along with IIS’s directory sercurity options to determine who is currently accessing your site. You can also grab the visitor’s IP address using the ServerVariables object. This article includes a question and answer from the Activer Server Pages mailing list, as well as an excerpt from the Visual InterDev 1.0 help files detailing all of the properties of the ServerVariables object. (4. How to develop your custom MyLink Control in Visual Studio.) Read the rest of this entry »

Posted in ASP.NET, C#, Delegate Controls, Deployment, DotNet, JavaScript, MOSS, My Links, My Site | Tagged: , , , , , , , | 2 Comments »