Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
To upload a document to sharepoint document library i did like this :

string strsite = "sharepoint site";
using (SPSite mySite = new SPSite(strsite))
{
using (SPWeb web = mySite.OpenWeb())
{
SPFolder folder = web.Folders["QEHS Manual"];
SPFileCollection filecol = folder.Files;
Boolean replaceExistingFiles = true;
string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
byte[] contents = new byte[Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];
SPFile addedFile = filecol.Add(filename, contents, replaceExistingFiles);
SPItem newItem = addedFile.Item;
newItem["No."] = txtno.Text;
newItem["Document Description"] = txtdocdescription.Text;
newItem["Document No."] = txtdocno.Text;
newItem["Custodian"] = txtcustodian.Text;
newItem["Revision No."] = txtrevno.Text;
newItem["Issue No."] = txtissueno.Text;
newItem.Update();
addedFile.Update();
}
}

the file gets uploaded. but when iam trying to pen it from sharepoint site, it is showning error.the error message is """the office open xml file xxx cannot be opened because there are problems with content""" can anyone pls help me..
Posted
Updated 21-Feb-12 23:17pm
v2

1 solution

use another overload method for
<b>myLibrary.Files.Add();</b>

where it will take hashtable as argument.
provide all metadata arguement in the hashtable

HashTable table = new HashTable() ;
table["field_name1"] = "field value1"
table["field_name2"] = "field value2"

send this hashtable object as arguement to the
myLibrary.Files.Add() method.

this might help....
 
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