sharepoint 2010 - Upload file with meta data and checkin to sharpoint folder using Client Object Model -
hi i'm trying upload file sharepoint 2010 using client api meta data , checkin file after i'm done. below code:
public void uploaddocument(sharepointfolder folder, string filename, boolean overwrite) {
var fileinfo = new fileinfo(filename); var targetlocation = string.format("{0}{1}{2}", folder.serverrelativeurl, path.altdirectoryseparatorchar, fileinfo.name); using (var fs = new filestream(filename, filemode.open)) { spfile.savebinarydirect(mclientcontext, targetlocation, fs, overwrite); } // doesn't work spfile newfile = mrootweb.getfilebyserverrelativeurl(targetlocation); mclientcontext.load(newfile); mclientcontext.executequery(); //check out make sure not create multiple versions newfile.checkout(); // use overwritecheckin type make sure not create multiple versions newfile.checkin("test", checkintype.overwritecheckin); mclientcontext.load(newfile); mclientcontext.executequery(); //spfile uploadfile = mrootweb.getfilebyserverrelativeurl(targetlocation); //uploadfile.checkout(); //uploadfile.checkin("some version comment i'd add", checkintype.overwritecheckin); //mclientcontext.executequery();
}
i'm able upload file can't add meta data , file checked out. want add meta data , checkin file after i'm done.
my sharepointfolder class has serverrelativeurl of folder path upload to. appreciated.
you need credential before executequery(); , savebinarydirect();
for example:
mclientcontext.credentials = new networkcredential("loginid","loginpw", "logindomain"); spfile newfile = mrootweb.getfilebyserverrelativeurl(targetlocation); mclientcontext.load(newfile); mclientcontext.executequery();
Comments
Post a Comment