Skip to main content

Posts

Showing posts from 2014

PATH OF DOOM

Disable Loopback Check

There is a security check in Windows 2008 which was introduced since the 2003 server version. This check ensures that a web application cannot be accessed using a fully qualified domain name on the host machine.  If you try to do so, the system returns an access denied error (401.1 error).  In actual fact, the login even though is correct will get challenged and produce a logon failure if you check the event log. The way to fix it is to make changes to the registry by following the steps below: Login to the Windows File Server Open regedit Allow other machines to access share using aliases Change Disable Strict Name Checking in the registry Browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters Add a DWORD named DisableStrictNameChecking Set value to 1 Also Proceed to HKLM:\System\CurrentControlSet\Control\Lsa\MSV1_0 -Name “BackConnectionHostNames” and add the FQDN of the web application to it.  

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

Set Page Programmatically

The page title in SharePoint is located in the content place holder called PlaceHolderPageTitle.   You can change it by referencing the place holder and setting a value in.   ContentPlaceHolder cp= (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitle"); cp.Controls.Clear(); cp.Controls.Add(new LiteralControl("The Title here"));   QED