Friday, April 24, 2009

Create Custom Policy File for SharePoint WebPart

Now you can run your code without modify FULL trust in WEB.Config file.
Below Steps to create Custom Policy File for WebPart.
  • Copy WSS_Minimal.config fole from ...\12\Config\ folder.
  • Rename to MyCustom_minimal.config.
  • Now Add below Code to this config file as per given location.

Add below code


Code Start Here Code End Here
  • Now Create Your PublicKey's Blob file as per below.
  • Open VS's command Promt and RUN below Command

sn -p YourStongNameFile.snk PublicKeyOnly.snk

YourStrongNameFile.snk = Your Projects SNK
PublicKeyOnly.snk = New creted PublicKey

Now Create Blob as below command.

sn -tp PublicKeyOnly.snk

Now your PublicKey's BLOB created like below (here Example)


Copy New Blob and past in above config file.

  • Put your config file in ...\12\Config\ folder.
  • Add one tag in config file below WSS_Medium,WSS_Minimal trust level like below.

    Also change Trust Level WSS_Minimal to MyCustom_Minimal.


Saturday, April 4, 2009

Create SharePoint WebPart using Visual Studio SharePoint Extension

  • Install Visual Studio SharePoint Extension.
  • Open Visual Studio and create New Project > Select SharePoint as Project Type > Select Web Part project template.
  • Then open Webpart1.cs file and add below things in render method.

protected override void Render(HtmlTextWriter writer)

{

writer.write("My First Web Part.");

}

  • Open Property Window of this project and Go TO Debug Tab and add your site URL to Start browsing with URL http://MyPC:100/MyFistSite/" (As per below Image)







  • Right Click on Project in Solution Explorer and Select Deploy.
  • After Successfully Deploy open your SharePoint site and Add Your First Web Part on your Web Part Page.

Very Easy to work with SharePoint Web Part.