October 28, 2009

Apply Custom Policy file to SharePoint Web Part

At the time of deployment of webpart, it is not possible for you to deploy DLL in GAC or have FULL trust level in the selected website.

In such case you can use custom policy file to come out from the problem.
Here are the steps to apply custom policy file to for your webpart(s).
·        Navigate to 12 hive\config folder.
·        Take a copy of WSS_Minimal.config file
·        Rename to [CompanyName]_minimal.config.
Open the new config file and add below code lines into the file as per given location. Add below code

 </NamedPermissionSets>

<CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="Nothing">

<IMembershipCondition class="AllMembershipCondition" version="1" />

<!-- New Code Lines added -->

<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust">

<IMembershipCondition class="StrongNameMembershipCondition" version="1" PublicKeyBlob="[Paste your Public Key BLOB]">

</IMembershipCondition>

</CodeGroup>

<!-- New Code Lines completed -->


Save the file. Don’t close it.

You need to add Public Key’s Blob file in addition to the above lines. To create the Blob you can follow the step below.

Open Start > All Programs > Microsoft Visual Studio 2005 > Visual Studio Tools > Visual Studio Command Prompt.

Type the following command
sn -p YourStongNameFile.snk PublicKeyOnly.snk

Where YourStongNameFile.snk is Your Projects SNK (Strong Name Key) file and PublicKeyOnly.snk is New creted PublicKey 

After you run the above command run the beloow command to create Blob:

 sn -tp PublicKeyOnly.snk

You will get your PublicKey's BLOB like below sample

 0024000004800000940000000602000000240000525341310004000001000100f9edc

57832372d0722d0ac9c068a482b47070d01b98ef1d7edd12eeec895e2a3d361220aef6

81d18c0cff1b2a9e606a18d968f6d4cceb148077c961d3e014a22b4049fb9c49c424f39e

6f192b27d961978ea766734432ce913b003b4085d7be21be2c570aa7c5a17506a25dac

84c2dd1ff037c22e147ab7ac563498b8602f8cf

 Copy this new blob and paste in config file in place the text “[Paste your Public Key BLOB]
that you kept open.

Save and close the config file.

  • Put your config file in 12 hive\Config folder.
  • Open you existing config file of your site and add one tag in config file under WSS_Medium,WSS_Minimal trust levels tags.

<securityPolicy>

<trustLevel name="WSS_Medium"  policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_mediumtrust.config" />

<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_minimaltrust.config" />

<!—Newly added code lines à

<trustLevel name="CompanyName_Minimal"  policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions \12\config\CompanyName_Minimal.config" />

<!—Newly added code lines end à

Now you have reached to the last step of the configuration,  change Trust Level WSS_Minimal to [CompanyName]_Minimal.

<trust level="CompanyName_Minimal" originUrl="" />

Save and close the config file.

Thats it J

If you have any questions you can reach out our SharePoint Consulting team here.

October 26, 2009

Enable Anonymous access in your SharePoint site

Many times you create websites in SharePoint. You assign different ports to access the site.

But what if you want to make the site internet facing and you want other to access the site with logging in to your site?

Yes this is possible.

Here are the steps to make a website as internet facing website.

1. Open Central Administration website of MOSS and navigate to

Central Administration > Application Management > Authentication Providers

The screen will look like below:




2. Select your web application that you want to enable anonymous access, from web application dropdown as displayed in below image.




3. Click on “Default” under Zone column. This will redirect to a new page. Check “Enable Anonymous Access” and click “Save” button.


4. Close Central Administration site.

5. Open the website that you selected for anonymous access. Login using administrator rights and navigate to Site Actions > Site Settings > People and Groups

6. Click “Site Permissions” from quick links. This will open up a new page as here:




7. Click on Settings under page header. Select “Anonymous Access”.




8. Close the browser and you are done.

If you have any questions you can reach out our SharePoint Consulting team here.

By: Alpesh

Display data using SharePoint List GUID

If you have to show data from SharePoint List using CAML (Collaborative Application Markup Language) required looping thru each item in list. This method takes bit long time to execute when you have large data in list.


Here is the one of the simple method to retrieve data from a SharePoint List by user selected view that doesn’t require CAML.

I have given some abstracts here:

// My list name is VerbList
// GUID of the list is F9037F57-6DEB-4BA8-B1BA-85A0995DE882

SPList listName;
DataTable ListDataTable=new DataTable();
SPListItemCollection listItemColl=
listName.GetItems(qry, "{ F9037F57-6DEB-4BA8-B1BA-85A0995DE882}");
ListDataTable =listItemColl.GetDataTable();

In above syntax code lines

listName is object of SPList,where my data is stored.

qry is Query for which data to be displayed.

F9037F57-6DEB-4BA8-B1BA-85A0995DE882 is the GUID of the SPView from where I have to fetch data.

Make sure you use the GUID in Upper Case.

Retrived data will be stored in ListDataTable, you can use the data as you wish.

If you have any questions you can reach out our SharePoint Consulting team here.
By: Nehali

October 15, 2009

How-To: Add intellisense support for Jquery inside UserControl page in Visual Studio 2008 IDE

If you have just downloaded and referenced Jquery , you might be wondering how to add intellisense support for the same in user control.


A blog post by scott gu shows very nicely how microsoft has included a hotfix for visual studio 2008 sp1 which enables jquery intellisense support (provided you also reference the jquery vsdoc file in your project).



I was trying out JQuery on normal aspx page and it worked just fine. However I soon ran into problem while using it in a user control, the intellisense simply was not working. I did a quick work around for the same which is as follows:

Just write down if statements within your user control which evaluates to false always and reference the jquery script file there. Note I already have a referenced jquery lib in my master page, and I don’t want it to be rendered a second time here, hence the if statement.

This code will server two purposes: firstly it will allow visual studio IDE to detect and display intellisense when you use jquery syntax in your user control, secondly it won’t show up in the rendered html since if always evaluates for false.


 
 
 
There may be other optimal solutions available out there, but this code did the trick for me and it can be removed before publishing the site for production purposes.

If you have any questions you can reach out our SharePoint Consulting team here.

Posted By: Bhavyesh