Skip to main content

Posts

Copy files from a document library to a files system by looping through all folders and subfolders in a library

If you have a need to copy file files from a document library to a SharePoint files system specifically the layouts folder.      private void LoopSubFolders(string folderPath, SPFolderCollection subFolders)         {             string templatePath = SPUtility.GetGenericSetupPath("TEMPLATE");             string FolderPath = Path.Combine(templatePath, @"LAYOUTS\ATP\");             try             {                 foreach (SPFolder folder in subFolders)                 {                     if (folder.Name.ToLower() != "forms")                     {                         string folderN...

Delete all files and folders in a document library

Are you looking to delete all files and folders in a document library, look no further. Ensure your users are empowered to do so by elevating their privilege, allow unsafe update then loop through the library in question. SPSecurity.RunWithElevatedPrivileges(delegate()             {                 using (SPSite elevatedSite = new SPSite(SPContext.Current.Site.ID))                 {                     using (SPWeb web = elevatedSite.RootWeb)                     {                         web.AllowUnsafeUpdates = true;                         web.ValidateFormDigest();                         ...

Download a file from a document library

You can download a file from a file stream quickly by passing in a SPFile object and the path where you want it to be written to: static void DownloadFileUsingFileStream(SPFile file, string path)         {             byte[] filecontent = file.OpenBinary();             FileStream fs = new FileStream(path + file.Name, FileMode.CreateNew);             using (fs)             {                 BinaryWriter bw = new BinaryWriter(fs);                 bw.Write(filecontent, 0, filecontent.Length);                 bw.Close();             }         } QED

Add Web Visual Studio templates to SharePoint Project

Would you like to add the web user control to SharePoint 2007 project development.  Then open the project file with notepad and add {349c5851-65df-11da-9384-00065b846f21} to the ProjectTypeGUIDs node.   The necessary change is shown below: < ProjectTypeGuids > {349c5851-65df-11da-9384-00065b846f21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} </ ProjectTypeGuids >

Register client side scripts in code behind

Quick way to register client side scripts.     Let us take the css files first: CssLink cssLink = new CssLink (); cssLink . DefaultUrl = "/_layouts/appname/cssfiletoregister.css" ; this . Page . Header . Controls . Add ( cssLink );     string scriptPath = "/_layouts/appname/jstoregister.js" ; if (! this . Page . ClientScript . IsClientScriptBlockRegistered ( scriptPath )) this . Page . ClientScript . RegisterClientScriptBlock ( this . GetType (), scriptPath , "

SharePoint URLs

 Got this idea from a good source and I need a backup for when I would need it. 1. Token: ~sitecollection ~site 2. SharePoint Server Token <% $SPUrl:~sitecollection/...%> 3. Emedded Code: <%=SPContext.Current.Site.ServerRelativeUrl %> You can use the embedded code any where in application page and web parts but don't use it in master page and page layout even though they seem work, because master page and page layout can be customized. The embedded code is only allowed in the uncustomized pages. 4. SharePoint Control: You can use the value returned by this control as control attribute but this is more like an hack, but it works. If you don't want to use it directly in attribute, you can use asp.net literal. < a href =" " >     < SharePoint : CssRegistration name ="<% $SPUrl:~sitecollection/_layouts/MortalityDB/css/custom.css %>" runat ="server" after ="SharepointCssFile"/> Here is...

Get Publishing HyperLink Field Value

The Publishing hyper link field value has some properties that you may want to extract for your use. Properties like: NavigateUrl, Target, Tooltip, Description, IconUrl Just pass in the field value name in your list.  LinkFieldValue pvalue = new LinkFieldValue(footerItem["FooterLink"].ToString());   your pvalue will then contain goodies. QED