Posts

Showing posts from 2012

Programmatically upload file to SharePoint Document Library

Method 1 : Stream fStream = upfile.PostedFile.InputStream;                             byte [] contents = new byte [fStream.Length];                             fStream.Read(contents, 0, ( int )fStream.Length);                             fStream.Close();                             string Filename = upfile.FileName;                             string destUrl = SPContext .Current.Site.Url + "/" + myLibrary.Title + "/" + Filename;                             oweb.Files.Add(destUrl, contents); Method 2 : with metadata SPDocumentLibrary myLibrary = oweb.Lists[attachmentsLib] as SPDocumentLibrary ;                             byte [] fileBytes = upfile.FileBytes;                             string strDestUrl = myLibrary.RootFolder.Url + "/" + upfile.FileName;                              SPFile destFile = myLibrary.RootFolder.Files.Add(strDestUrl, fileBytes, true );                             destFile.Item[ &qu

Export Gridview to PDF

http://www.dotnetspider.com/resources/29759-Exporting-GridView-PDF.aspx

Using the SharePoint ‘Person or Group’ field in code

 string[] Groupname = PLPSurveyAttendees.CommaSeparatedAccounts.Split(',');                                     string Users = string.Empty;                                     foreach (string survueygroupname in Groupname)                                     {                                         SPGroup ogrp = oWeb.Groups[survueygroupname];                                                                            Users += ogrp.ID.ToString() + ";#" + ogrp.Name.ToString() + ";#";                                      }                                     if (Users.EndsWith(";#"))                                     {                                         Users = Users.Substring(0, Users.Length - 2);                                     }                                     oListItem["Survey Attendees Group"] = Users;

Delete SharePoint Lists Programmatically

 using (SPSite osite = new SPSite("SiteURL"))             {                 using (SPWeb oweb = osite.OpenWeb())                 {                     SPListCollection olistcoll = oweb.Lists;                     Hashtable ht = new Hashtable();                     foreach(SPList olist in olistcoll)                     {                         if (olist.Title.StartsWith("Test"))                         {                             ht.Add(olist.ID, olist.Title);                                                  }                     }                     foreach (Guid ID in ht.Keys)                         olistcoll.Delete(ID);                 }             }

Bind the SharePoint List Values to DropDownList using SPDataSource

<SharePoint:SPDataSource runat ="server"  ID="spMaster"  DataSourceMode="List" SelectCommand="<Query><OrderBy><FieldRef Name='SortOrder' Ascending='true' /></OrderBy></Query>" >                                 <SelectParameters>                                 <asp:Parameter Name="WEbUrl" DefaultValue="/SiteName/" />                                 <asp:Parameter Name="ListName" DefaultValue="Your List Name Here" />                                 </SelectParameters>                                 </SharePoint:SPDataSource>

Set DateTimeControl Region

DtDueDate.LocaleId = Convert .ToInt32( SPContext .Current.Web.RegionalSettings.LocaleId);

Create Folder in Document Library Programmatically

SPDocumentLibrary _MyDocLibrary = ( SPDocumentLibrary )_MyWeb.Lists[ "Library Name Here" ];                  SPFolderCollection _MyFolders = _MyWeb.Folders;                 _MyFolders.Add(_MyDocLibrary.RootFolder.ServerRelativeUrl + "/" + ListItemID + "/" );                               _MyDocLibrary.Update();

Hide the ChangeView option from SharePoint 2010 Ribbon

Based on the KISS principle, there has to be an easier way - and there it is: As an example, if you want to hide the change view, then you can just use the following CSS: <style> #Ribbon\.List\.CustomViews\.DisplayView-Medium{ display:none; } </style>

SharePoint Document Counter Counts The Document Downloads

http://www.fivenumber.com/sharepoint-document-counter-counts-the-document-downloads/

List Join operation in SharePoint 2007 / 2010

Approach  1 private   static   void  FetchAllListsDataJoinUsingLinq() {      using  ( SPSite  _spSite =  new   SPSite ( "<Site Url>" ))     {          using  ( SPWeb  web = _spSite.OpenWeb())         {              SPList  placeList = web.GetList(web.Url +  "/lists/TouristPlace" );              SPQuery  ospPlaceQuery =  new   SPQuery ();              DataTable  dtPlace = placeList.GetItems(ospPlaceQuery).GetDataTable();              SPList  cityList = web.GetList(web.Url +  "/lists/City" );              SPQuery  ospCityQuery =  new   SPQuery ();              DataTable  dtCity = cityList.GetItems(ospCityQuery).GetDataTable();              SPList  countryList = web.GetList(web.Url +  "/lists/Country" );              SPQuery  ospCountryQuery =  new   SPQuery ();              DataTable  dtCountry = countryList.GetItems(ospCountryQuery).GetDataTable();              List < TouristPlaceDetails > joinD

SharePoint List Template Id’s

http://mosshowto.blogspot.in/2009/04/sharepoint-list-template-ids.html

SharePoint 2010 Client Object Model: Introduction

http://www.codeproject.com/Articles/399156/SharePoint-2010-Client-Object-Model-Introduction

How to run .exe on a Web Page

<script> function LaunchApp() { if (!document.all) { alert ("This ActiveXObject is only available for Internet Explorer"); return; } var ws = new ActiveXObject("WScript.Shell"); ws.Exec("D:\\yourfile.exe"); } </script> More Info http://codereflex.net/how-to-run-exe-on-webpage/

Common list operations in SharePoint 2010

Image
This below link is a good blog for SharePoint i have ever seen. Nice Keep posting http://www.sharepointkings.com/search/label/Object%20Model Thanks. i picked up some snaps from the above link for my reference. 1) How to add validation for the field in the list 2).    How to add list validation 3).  How to add referential integrity (cascading delete or cascading restrict) to the relationhip list

Modify NewForm.aspx and EditForm.aspx in Moss 2007

1.Navigate to the SharePoint List/Library 2.Open the NewForm or the Edit Form 3.Append the following querystring to the url ?PageView=Shared&ToolPaneView=2 e.g. http://{yoursite}/Lists/listname/NewForm.aspx?PageView=Shared&ToolPaneView=2 http://{yoursite}/Lists/listname/EditForm.aspx?PageView=Shared&ToolPaneView=2 More Info http://www.dhirendrayadav.com/2010/08/modify-newformaspx-and-editformaspx-add.html http://www.sharepointkings.com/2008/05/how-to-edit-list-forms-like-newformaspx.html

Javascript PreSaveAction() in SharePoint 2010 Validation

Image
Go to SharePoint List Defalut Edit or Newform.aspx. over there you have to put the HTML Form WebPart. Inside the HTML Form Webpart you need add the following scripts tag and references. Download js files from here  http://sputility.codeplex.com/ <script src="/Registry/JSFiles/prototype.js" type="text/javascript"></script> <script src="/Registry/JSFiles/SPUtility.js" type="text/javascript"></script> <script type="text/javascript"> function PreSaveAction() { var item=SPUtility.GetSPField('Type of Report').GetValue(); // Choice filed Validation if(item=="Informer") {      alert("Please select the Value");      return false; } else { return true; }  } </script>​

SPUtility.js

Image
http://sputility.codeplex.com/ Installation To use the library, you can just upload SPUtility.js and prototype.js into a document library and put a Content Editor Web Part with some JavaScript code on whichever page you want to modify! Detailed instructions are on the  Installation  page. Usage Examples: Set a Text field's value SPUtility.GetSPField('Title').SetValue('Hello world!'); Set a Text field's value and make it read only SPUtility.GetSPField('Title').SetValue('Hello world!').MakeReadOnly(); Make a Choice field read only Before SPUtility.GetSPField('Status').MakeReadOnly(); After Set a People field and/or Make it Read Only SPUtility.GetSPField('Assigned To').SetValue('Menke, Kit'); SPUtility.GetSPField('Assigned To').MakeReadOnly(); Hide a field from view Before SPUtility.GetSPField('% Complete').Hide(); After