public SPListItem UploadFile(SPList listName)
{
SPListItem fileItem = null;
try
{
SPWeb web = listName.ParentWeb;
SPFolderCollection sfc =
web.Folders;
string path = web.Url + "/" + listName.Title.ToString(); // +"/" +
fileUpload1.FileName.ToString().Split('.')[0];
sfc.Add(path);
SPFile sfile = web.Files.Add(path
+ "/" + fileUpload1.FileName.ToString() +
System.IO.Path.GetExtension(fileUpload1.PostedFile.FileName),
fileUpload1.FileContent, true);
listName.Update();
fileItem = sfile.Item;
}
catch (Exception ex)
{
Message(lblerror, ex.Message);
}
return fileItem; // sfile.Item;
}
No comments:
Post a Comment