1

I am using the following code to upload a file to a SharePoint Document Library but it's not attaching the metadata:

private void UploadFileToSharePoint(string strInputFileName, string sDocLibraryName)
{
    SPWeb site = SPContext.Current.Web;
    SPList myList = site.Lists[sDocLibraryName];
    string destFileUrl = myList.RootFolder.ServerRelativeUrl + @"/New.txt";
    site.AllowUnsafeUpdates = true;
    // FileStream fileStream = File.Open(strInputFileName, FileMode.Open);
    byte[] strm = File.ReadAllBytes(strInputFileName);
    // newFile.CheckIn("File added");
    //SPListItem item = newFile.Item;
    //item.File.CheckOut();
    Hashtable ht = new Hashtable();
    ht.Add("Status Indicator", "hello");
    ht.Add("Status Description", Description.Text);
    ht.Add("Status", "Delayed");
    //item.Update();
    //item.File.CheckIn("File with metadata");

    myList.RootFolder.Files.Add(destFileUrl,strm,ht, true/*overwrite*/);
    myList.Update();
}

I am using this function call:

UploadFileToSharePoint(@"C:\check.txt", 
                        "Project Status" /* name of Dc Library*/ );   

1 Answer 1

1

I don't see where you add the metadata, i see you filling a hashtable and do nothing with it

Sign up to request clarification or add additional context in comments.

1 Comment

I have edited the question with full code..can you please check it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.