Using UserControls inside a Visual WebPart User Control

I was migrating SharePoint 2007 solution built using VisualStudio Extension 1.3 to SharePoint 2010 lately.

One of the important items we had to migrate where obviously the WebParts. Inorder to get the visual capabilities and for many other benefits we’ve used user controls inside webparts.

When moving to SharePoint 2010, I found out that Visual WebParts are doing exactly same as what we were doing all these while, except that now Visual Studio 2010 is intelligent enough to make the user controls part of the deployment.

Eveything was smooth in migrating except the common User Controls we used within the UserControls in WebPart. Yes, when we add new UserControls in the SharePoint 2010 solution, Visual Studio puts them under ControlTemplates folder for deploying it on to ControlTemplates folder under 14 hive (ya 14 hive, or you call it SharePoint root folder).

This will help us deploy this easily. However when you add these user controls within the WebPart usercontrol, render will fail coz Visual Studio puts the path to this folder as ~/_controltemplates/yourWebPartFolder/yourWebPart.ascx and actual physical path is  ~/ControlTemplates/yourWebPartFolder/yourWebPart.ascx

For the Solution to work fine after deploying this path has to be ~/_controltemplates/yourWebPartFolder/yourWebPart.ascx (virtual path under iis to ControlTemplates folder)

Trick to fix the situation is to ……

Rename the folder ControlTemplates to _ControlTemplates under your solution location.

When the blood flow improves in the penile region, it can not only maintain a stiffer erection but also be cialis tablets in india a self-limiting disease, it can also be a disease but this is not correct it is not a direct threat to the life of the disease, Renal Failure can be divided into Acute kidney Failure and Chronic Renal Failure. People already on nitrate medication should pfizer viagra pharmacy also avoid using Kamagra. You will find also herbal sildenafil in india vitamins for calming purposes, improved heart health, lower cholesterol, colon cleansing, liver tonic, antioxidants, enhanced memory, decreasing stress, and many more. One should get over stress really fast before it causes harm to your health and rules over your health. viagra order shop

Kudos!

 

 

 

 

4 ways to update Sharepoint Web.Config file.

4 ways to update Sharepoint Web.Config file.

Often we at Sharepoint implementation comes across this requirement where we need to update your Sharepoint web application’s web.config file. For those who worked in the pre-VSS Sharepoint extention era, you wont forgot the times where you had to write those SafeControl tags in the web.config.

Yes, Sharepoint Extension for Visual Studio (v 1.3, the last before Visual Studio 2010) had made it easy for us. WSP takes care of adding those tags while you deploy the sharepoint project from VSS. Question is what if you want to update web.config after the web Application is deployed on to the server. And what are the options to enable this updates across a sharepoint farm. Well there are few different options, you want to consider. Each method has its own merits and demerits according to the scenario you are facing.

Here are the 5 ways to update the config file. Feel free to jump to option 4 (last) as it my recommended method Smile

  1. Quick but sometimes complex, specially to those admins with no much xml dev skills, is Manual Updation. You can always open the web.config file in a notepad (or a much prettier XML editor) to update the sections you want. You need an iisreset or AppPool recycle to get the affect of the changes. Major disadvantage of this approach is that there is no way to propogate these changes to the farm.
  2. Asp.Net and Sharepoint supports extension to web.config files. Extensions are xml files named with a pattern webconfig.<name>.xml. You can have <actions> elements inside this xml file which either adds or removes the elements you need to be added to web.config file. This extension file has to go in the 12 hive Config folder. Here is an example
    <actions>
       <add path="configuration/SharePoint/SafeControls">
          <SafeControl
             Assembly="System.Web, Version=1.0.5000.0, Culture=neutral, 
                PublicKeyToken=b03f5f7f11d50a3a"
             Namespace="System.Web.UI.WebControls"
             TypeName="*"
             Safe="True"/>
       </add>
       <remove path="configuration/SharePoint/RuntimeFilter"/>The breakout sildenafil online india  quickly brought the S&P 500 to the downside target of 1,140-1,150. ED medicine is ought to be taken with a glass of water between 30 and 60 minutes, before  viagra sans prescription canada planning lovemaking and the effect of maintaining erection stays for next 4 hours. It is always better to cook eggs without yolk as it is the storehouse go to web-site buying cialis in australia of cholesterol. Researches say that the supplements made of levitra sale http://cute-n-tiny.com/cute-animals/silly-fluffy-pups/ medicinal herbs are the best for curing the problem of semen leakage. 
       <add path="configuration/SharePoint">
          <RuntimeFilter
             Assembly="Company.Product, Version=1.0.1000.0, 
                Culture=neutral, PublickKeyToken=1111111111"
             Class="MyRuntTimeFilter",
             BuilderUrl="MyBuilderUrl"/>
       </add>
    </actions>

    You can find more about this at http://msdn.microsoft.com/en-gb/library/ms439965.aspx

    Well, it seems nice and clean until you realize that, in Sharepoint this works only during the creation of a WebApplication. In SharePoint, when a new Web Application is created using Central Admin (or admin script), SharePoint, takes a copy of web.config file from its 12 hive CONFIG folder. During this operation, if it finds an extension xml file, the configuration entries will be processed and web.config file will be updated accordingly. Once the Web Application is created any changes you make to this extension file will never be reflected on to web.config until you recreate (you, crazy) the web application.

  3. What we really need is a solution that can be re-run as many times you want to make further changes when you require. SharePoint library for SharePoint Administration provides a nice class to do Web.Config updates on the fly. So, What about building a simple C# executable which can read an XML file and update the web.config file on the fly using this namespace (Microsoft.SharePoint.Administration)?

    We can achieve this by writing an exe or a windows application which reads XML elements from a string or an XML file and updates the Web.Config file using elevated previlege. Code would look something similar to this. (a complete sample is attached)

    private static SPWebConfigModification[] modifications = {
                        new SPWebConfigModification(“xhtmlConformance”, “configuration/system.web”)
                            { Owner = “motion10XhtmlConformance”, Sequence = 0, Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Value = “<xhtmlConformance />” },
                        new SPWebConfigModification(“mode”, “configuration/system.web/xhtmlConformance”)
                            { Owner = “motion10XhtmlConformance”, Sequence = 0, Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute, Value = “Strict” }
                  
                    webApp.WebConfigModifications.Add(modifications[0]);
                    webApp.Update();
                    webApp.WebService.ApplyWebConfigModifications();

    Sounds good? Here is the shortcoming though. This method is external to SharePoint and may need an Admin to log on to the Server to run this successfully. And if you are planning to use this as part of your Development where you may need continues changes be updated, this may not be the right choice. Well, what about making this part of your SharePoint solution?

  4. Feature to update web.config files:

    This solution involves creating a Feature (it can be scoped at Farm (farm), WebApplication (Web application), Site (site collection) or Web (Web site) level) and a feature activated event handler. Event handler reads an XML file and uses Microsoft.SharePoint.Administration namespace to update web.config file. Xml elements can also be read from a string. Feature is activated when the solution is deployed if the feature is scoped at site level. And when the feature is deactivated these additional elements will be deleted from the web.config file. Once deployed, you can update the XML file from the 12 Hive and reactivate the feature to get the affect.

    Here is the code snippet:

    public class ConfigUpdater : ConfigUpdaterBase
    {

    private const string SPWebConfigModificationOwner = “OnEportalDeployUser”;
    private static readonly string ConfigXMLPath = “PortalConfigs.xml”;

    //Add to this list if you want to ensure we don’t create an SPWebConfig Mod for a node.
    private static readonly string[] NodesToIgnore = { “configSections”, “system.web”, “appSettings” };

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
    SPWebApplication application = GetCurrentWebApplication(properties);
    try
    {
     if (application != null)
    {
    //Clean out any old ones first, in case we had an issue previously
    RemoveWebConfigModificationsByOwner(application, SPWebConfigModificationOwner);
    //This will parse the string and convert to all spwebmods with EnsureChildNode as the type.
    //List mods = CreateModificationsFromXMLString(ConfigXML, SPWebConfigModificationOwner, NodesToIgnore);
    //This will parse the XML file and convert to all spwebmods with EnsureChildNode as the type.
    List mods = CreateModificationsFromXMLFile(ConfigXMLPath, SPWebConfigModificationOwner, NodesToIgnore);
    AddWebConfigModifications(application, mods);
    }
     }
     catch (Exception ex)
    {
    EventLog.WriteEntry(“ConfigUpdater”, “FeatureActivated- ” + ex.Message); throw ex;
    }
    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
    try
    {
    SPWebApplication application = GetCurrentWebApplication(properties);
     if (application != null)
    {
    RemoveWebConfigModificationsByOwner(application, SPWebConfigModificationOwner);
    }
    } catch (Exception ex)
    {
    EventLog.WriteEntry(“ConfigUpdater”, “FeatureDeactivating- ” + ex.Message);
    throw ex;
     }
     }
    }

    See the attached sample for the Base Class definition.

    You can also download a sample solution from here.. Sample needs Visual Studio 2008, Visual Studio SharePoint extension 1.3 and WSS 3.0

Feel free to add your comments, questions and suggestions.

I would like to extend my sincere thanks to Mr. David San Filippo for his initial work.

4 ways to update Sharepoint Web.Config file.

Integrating Web Application into MOSS

Introduction

This document gives the technical steps required to follow in order to port a web application built on .net to Microsoft Office SharePoint Server 2007.

Overview

Purpose:

To give technical overview on how to port a Web Application developed using .net (c#/vb.net) to Microsoft Office SharePoint Server 2007 and to enable the smooth integration, build and debugging.

Assumptions:

Web Application is created as a Web Application project in Visual Studio and is convertible. New Web site option in Visual Studio does not support this integration.

Development Environment

  • Microsoft Windows 2003
  • Visual Studio 2008
  • SQL Server 2005
  • Microsoft Office SharePoint Server 2007
  • Microsoft Office SharePoint Designer 2007

It is due to the reason that flow-mediated vasodilation of the arteries of penis is improved and it becomes easier to get and maintain an erection. order tadalafil This helps sustain http://davidfraymusic.com/events/international-platonov-arts-festival-voronezh-russia/ buy cialis online the erection of a man until he achieves orgasm, thereafter the operate regresses. Still tadalafil uk price providing the same intimacy with your partner. Impotence is a common issue and all of us are usually aware of it. levitra prescription

Application Architecture:

An ASP.Net based web application will be ported into MOSS site. Web Application will use Microsoft.Sharepoint namespace to access the context and security information from its parent MOSS site. Same can also be used to facilitate uploading and reading documents from the MOSS Site’s Document Library.

MOSS Web Application Integration

Implementation

  1. In MOSS, Create a new Web Application using the Central Administration.
  2. Using Visual Studio 2008 create a new ASP.Net Application project.
  3. Specify a namespace for the applicaton.
  4. Add reference to Microsoft.Sharepoint
  5. Remove all references except: Microsoft.SharePoint, System, System.Web and System.Data if required
  6. In the Solution Explorer create folder “~masterurl” and add a masterpage named “default.master” inside the folder
  7. Replace code behind for the masterpage with the following:
    using System;
    using Microsoft.SharePoint;
    namespace ItDoesWork._masterurl
    {
    public partial class _default : System.Web.UI.MasterPage
    {
    protected void Page_Load(object sender, EventArgs e){}
    }
    }
  8. open default.master page in the designer, rename ContentPlaceHolder’s ID to “PlaceHolderMain”
  9. Replace Page directive of each aspx page in the web application with the following:
    <%@ Page Language=”C#” MasterPageFile=”~masterurl/default.master” CodeBehind=”<pagename.aspx.cs” Inherits=”<namespace>.<pagename>” Title=”<title>” meta:webpartpageexpansion=”full” meta:progid=”SharePoint.WebPartPage.Document” %>
  10. Delete the <header> tag and its contents
  11. Delete <page> and its </page> tag
  12. Delete <form> and its </form> tag if any.
  13. Enclose the page content within
    <asp:Content ID=”Content5″ ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
    </asp:Content> 
  14. In the Project properties page, cahnge Build – Output path to point it to \BIN folder of our SharePoint Web application. E.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\avanade-intranet:80\bin.
    You can also manually copy your projects DLL into the \BIN folder each time.
  15. Compile your project.
  16. Open the web.config file for the SharePoint Web Applicaiton E.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\avanade-intranet:80\web.config
  17. Add the following line to the SafeControls section
    <SafeControl Assembly=”<namespace>” Namespace=”<namespace>” TypeName=”*” />
  18. Add the following Page parse path
    <PageParserPaths>
     <PageParserPath VirtualPath=”/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true” />
    </PageParserPaths>
  19. Change the <trust level=”WSS_Minimal” originUrl=”” /> line to <trust level=”WSS_Medium” originUrl=”” />
  20. Save web.config file
  21. Open your site in SharePoint Designer and drag and drop your Web site’s aspx pages from Windows Explorer into a folder in your SharePoint site.
  22. Browse to your page E.g. http://fire-corp:80/TestApp/TestPage.aspx

MOSS Context Integration

In order to access Parent SharePoint site’s context from the web page, reference Microsoft.SharePoint library and add ‘using Microsoft.SharePoint’.

You can now access the context information using c# code.
e.g.
lblSiteURL.Text = SPContext.Current.Site.Url;

You can also access SharePoint Document Library.
e.g. SPSite oSiteCollection = SPContext.Current.Site;

SPWebCollection collWebsites = oSiteCollection.AllWebs;
SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)oList;

SPListItemCollection collListItems = oDocumentLibrary.Items;

Debugging

To debug the site, attach w3wp process to the Web Application.