Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi tech geeks,
I want to upload a document through the following code in the sharepoint document library
The issue is that the code work fine but i just want an addtitional sting parameter to be passed with the method say liitle descrptn abt file and also want to retrive the same while i will show the files in the gridview
So i just want to know that how to pass an addtional string paratemer
as these are all sharepoint methods i can modify it and same time i want to use the byte stream only
Some one kindly help

if (FileUpload1.PostedFile.ContentLength > 0)
{
System.IO.Stream strm = FileUpload1.PostedFile.InputStream;
byte[] byt = new byte[
Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];

strm.Read(byt, 0, Convert.ToInt32(FileUpload1.PostedFile.ContentLength));
strm.Close();

SPSite site = new SPSite(SPContext.Current.Site.Url);
SPWeb objWeb = site.OpenWeb();
SPFolder mylibrary = objWeb.Folders["UploadedDocs"];

objWeb.AllowUnsafeUpdates = true;

SPFile file = mylibrary.Files.Add(System.IO.Path.GetFileName
(FileUpload1.PostedFile.FileName), byt, SPContext.Current.Site.RootWeb.CurrentUser, SPContext.Current.Site.RootWeb.CurrentUser, System.DateTime.Now, System.DateTime.Now);
}
Posted

1 solution

Hi

Once the file is created you can access the metadata/columns in the library as a list item by using the following code:
SPListItem item=file.ListItemAllFields;
item["Description"]="some description about the file";
item.Update();

I hope this will do the job.. If you have any questions please reply to the answer :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900