by Keyvan Nayyeri via Keyvan Nayyeri on 7/9/2007 3:20:56 AM
The ability to upload files to a weblog and manage them via folders is a new feature in Community Server 2007 that is accessible via control panel and Manage Blog Files menu.
There are some newly added APIs to work with these folders and files for each particular blog. In this post I talk about them shortly.
CommunityServer.Blogs.Components.WeblogFile and CommunityServer.Blogs.Components.WeblogFiles are two classes that play a role in this scenario. WeblogFile is the code representation of a weblog file or folder and WeblogFiles is a method factory to work with files and folders and to get, add or delete them.
WeblogFile has four read only properties that you can create an instance based on them via its public constructor. These properties specify some information about it.
WeblogFiles class is where you can get the benefit of this WeblogFile class in order to get, add or delete a file or folder with some static methods that are provided there.
Here I give some examples.
Using AddFile() method you can add a file to storage system. You can pass this file as stream or as array of bytes. Following example uses the second overload to upload a file to "Sample" folder of current blog.
void AddFileFromPath(string path)
{
WeblogFiles.AddFile(CSContext.Current.Section.ApplicationKey, File.ReadAllBytes(path),
"Sample", Path.GetFileName(path));
}
GetFile() gets some parameters for a specific file and returns an instance of WeblogFile. In the example below, I get an instance of WeblogFile object for "Sample" folder and the passed file name as parameter.
WeblogFile GetFileFromName(string fileName)
WeblogFile file = WeblogFiles.GetFile(CSContext.Current.Section.ApplicationKey,
"Sample", fileName);
return file;
And the DeleteFile() method is able to get a file name and delete it from storage as you see in the next code example.
void DeleteFileFromName(string fileName)
WeblogFiles.DeleteFile(CSContext.Current.Section.ApplicationKey, fileName);
The last common method is GetFiles() which returns a list of WeblogFile objects for a specified folder.
List<WeblogFile> GetFilesFromFolderName(string folderName)
return WeblogFiles.GetFiles(CSContext.Current.Section.ApplicationKey, folderName);
Now playing: Isaac Albeniz - Asturias
Original Post: CS Dev Guide: Weblog Files
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.