Showing posts with label Asset Library. Show all posts
Showing posts with label Asset Library. Show all posts

Wednesday, February 4, 2015

How to upload image or video or Document in asset library using Server Object Model SharePoint?

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{ web.AllowUnsafeUpdates = true;
string value = ddlformat.SelectedItem.Text;
web.AllowUnsafeUpdates = false;
Stream StreamImage = null;
if (uploader.HasFile)
{
StreamImage = uploader.PostedFile.InputStream;
}
SPList pics = web.Lists.TryGetList("AudioLibrary");
string fileExt = Convert.ToString(uploader.FileName);
fileExt = fileExt.Split('.')[0];
fileExt= fileExt + value;
if (pics != null)
{
SPListItem picItem = pics.Items.Add();
if (pics != null)
{
web.AllowUnsafeUpdates = true;
// Stream ggg=new Stream();
SPFile ofile = pics.RootFolder.Files.Add(fileExt, StreamImage, true);
ofile.Update();
web.AllowUnsafeUpdates = false;
}
}
}
}