I can upload documents into sharepoint via following code. My document library has 3 mandatory columns, “Project Title”, etc. Whats the code to ensure that when I have successfully uploaded the document, the column data are reflected too.
Thank you!
protected void Button2_Click(object sender, EventArgs e)
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
DocumentAttached(myWeb);
}
//The Function for uploading a File in a Document Library is Below:
public void DocumentAttached(SPWeb site)
{
if (FileUpload1.HasFile)
{
SPFolder folder = site.GetFolder("Innovation Submission");
SPFileCollection files = folder.Files;
Stream fStream = FileUpload1.PostedFile.InputStream; //path of the file to upload
byte[] contents = new byte[fStream.Length];
fStream.Position = 0;
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
string Filename = FileUpload1.FileName;
string URL = SPContext.Current.Site.Url + "/RIDepartment/Innovation%20Submission/" + Filename;
SPFile currentFile = files.Add(URL, contents);
}
}
If you want to assing your custom fileds after uploading a document, you can use SPFile.Item property i.e.: