Skip to main content

Posts

Showing posts from September 9, 2012

How to iterate through all items from a folder which is present in 14 hive layouts folder and add them as drop down options?

Suppose you have a Combo box( it is for drop down in asp.net) object  called "ddmItems". First get the path to the file present in the 14 hive layouts folder as below string   targetPath =  SPUtility .GetGenericSetupPath( @"TEMPLATE\LAYOUTS\FOLDER_NAME\TARGET_FOLDER_NAME" ); Now iterate in  the TARGET_FOLDER present in the 14 hive layouts folder and  add to the combo box object(ie. “ddmItems”). foreach   ( var   directoryItem   in   Directory .GetDirectories(targetPath)) {          DirectoryInfo   info =   new   DirectoryInfo (directoryItem);          string   fileName = info.Name;       //Check whether the file name is already added to the drop down          if   (!ddmItems.Items.Contains(fileName))        {          ddmItems.Items.Add(fileName);        } } Hope this will help cheers Pradeepa Achar

How to upload document to each item of the Sharepoint list?

Suppose you have a variable which is holding path to the file including the filename along with the extension. string srcUrl = Target_Path_To_The_Directory + "\\FILE_NAME.doc" ; Using the following code you can upload file to the item of the SharePoint list SPList list=SPContext.Current.Web.Lists[“LIST_NAME”]; SPListItem item=list.Items.Add(); FileStream fStream = File.OpenRead(srcUrl); string fileName = fStream.Name.Substring(3); byte[] contents = new byte[fStream.Length]; fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); item.Attachments.Add(filename, contents); item.Update(); Hope this will help Cheers Pradeepa

How to get the path to the 14 hive layouts folder programmatic ally using C# ??

Hi All,     I had come across a situation where i had to access to one of the folder in 14 hive layouts folder. I accomplished in this way. string pathToTargetFolder = SPUtility.GetGenericSetupPath (@"TEMPLATE\LAYOUTS\FOLDER\TARGET_FOLDER"); The variable "pathToTargetFolder" now holds the path to the folder "TARGET_FOLDER" in layouts folder. Hope this will help. Pradeepa Achar