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

Archive for the ‘DotNet’ 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 »

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 »

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 »

SharePoint Exception Handling and Logging

Posted by PANVEGA on January 21, 2009

Error and exception handling is very important in creating a robust and high quality system and more importantly for trouble shooting. Error and exception handling must be done correctly so that potential issues with the system can be diagnosed quickly.

The Basics

  • Always display a high level abstract message to the user when an error occurs or an exception is thrown rather than a low level exception message that the user will not understand. The low level specific error message should be written to the log file.
  • Check objects, values, properties etc before using them so that unexpected exceptions are not thrown.  For example
    • When obtaining an object always check the object is not null before using it.
    • Always check strings to make sure they are not empty or null i.e. String.IsNullOrEmpty(“aString”)
  • Never use try catch blocks to control the logic of your code, it is more efficient to use if/else statements and only throw exceptions when nothing else can be done.
  • When casting always check the object can be cast to the particular object. For example:

if(MyObject is String)


// Cast object your object

} Read the rest of this entry »

Posted in ASP.NET, C#, Deployment, DotNet, MOSS | Tagged: , , , | Leave a Comment »

Introduction in Custom WF Activities

Posted by PANVEGA on January 20, 2009

Microsoft Office SharePoint Designer 2007 allows non-developers to create custom workflows in a straightforward way by using the workflow designer it provides. During the process, the user “glues” together different activities that represent the steps for the workflow. There are numerous activities one can use and the list is extensible. Developers can use Microsoft Visual Studio 2005 to build additional activities and deploy them, so that they are available in Office SharePoint Designer 2007.

My example in the post extendes the default out of the box Activity in the SP Designer (Copy List item). In the default activity you can only copy an item in the same site. I added a new attribute DestinationListUrl which copies the select item from the root list by using the SP Object Model to the destination list in an other site collection.


On Codeplex you find some useful custom SP Activities Read the rest of this entry »

Posted in Administration, C#, Deployment, DotNet, MOSS, Object Model, SPDesigner, Workflows, XML | Tagged: , , , , , , , , | Leave a Comment »

How to add a SPFeatureReceiver to a Custom ListInstance?

Posted by PANVEGA on January 19, 2009

In reference to my previous post about binding a Custom ContentType to a new ListInstance, I wanna solve this issues belowe with a SPFeatureReceiver class in Visual Studio.

First off the default view of your list does not contain those custom columns. When you select the item you will of course see all of your columns but they aren’t listed in the default view. Secondly the default content type for the list is still available to the user. In the case of a generic list the “Item” content type is still present. So when a user enters a new item they are able to select Item or your custom content type. This may not be desirable. Also if you are using the API to insert a new item into the list it will use the list’s default content type instead of the one you may be expecting. Once again this may not be desirable.

To overcome these restrictions we’re going to create a generic feature receiver that can be reused on any implementation using this technique. Read the rest of this entry »

Posted in C#, Custom Content Types, Deployment, DotNet, Event Receivers, MasterPage, MOSS, Object Model, Site Definition | Tagged: , , , , , , , , | Leave a Comment »

Retreive recursive all SP Subwebs with current User Permission

Posted by PANVEGA on November 20, 2008

As an alternative to programming against the SharePoint web services you can use the SharePoint object model. The object model can be used when the application will run on the server where SharePoint is installed (such as a console or WinForm application) or in assemblies that are run within a site (such as a Web Part or Webservices).

One of the great things about the object model is that it is security trimmed, so you can usually just ask for items that the user has permissions for. However, there may be items that the user can access but the user still doesn’t have access to perform a specific task– which is a great reason to check for permissions before attempting an operation


I need a way to retreive a existing Subwebs Sites from SharePoint how the current User has the rights to access the site. This information should be used to store the items in a XMLDocument and returns the content to a custom SharrePoint WebService method. Read the rest of this entry »

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