Sharepoint 2010 Upload file using Silverlight 4.0 -
Sharepoint 2010 Upload file using Silverlight 4.0 -
i trying file upload silverlight(client object model) sharepoint 2010 library.. please see code below..
try{ context = new clientcontext("http://deepu-pc/"); web = context.web; context.load(web); openfiledialog ofiledialog = new openfiledialog(); ofiledialog.filterindex = 1; ofiledialog.multiselect = false; if (ofiledialog.showdialog().value == true) { var localfile = new filecreationinformation(); localfile.content = system.io.file.readallbytes(ofiledialog.file.fullname); localfile.url = system.io.path.getfilename(ofiledialog.file.name); list docs = web.lists.getbytitle("gallery"); context.load(docs); file file = docs.rootfolder.files.add(localfile); context.load(file); context.executequeryasync(onsiteloadsuccess, onsiteloadfailure); } } grab (exception exp) { messagebox.show(exp.tostring()); }
but getting next error
system.security.securityexception: file operation not permitted. access path '' denied. @ system.io.filesecuritystate.ensurestate() @ system.io.filesysteminfo.get_fullname() @ imageuploadsilverlight.mainpage.fileupload_click(object sender, routedeventargs e)any help appreciated
thanks
deepu
silverlight runs restricted access client user's filesystem. when using open-file dialog, can name of selected file within parent folder, length of file, , stream read info in file, not much more that. can't read total path of file selected, , getting exception because attempting exactly that.
if want read entire content of file byte array, you'll have replace line
localfile.content = system.io.file.readallbytes(ofiledialog.file.fullname);
with like
localfile.content = readfully(ofiledialog.file.openread());
the readfully
method reads entire content of stream byte array. it's not standard silverlight method; instead taken this answer. (i gave method quick test on silverlight, , appears work.)
silverlight sharepoint-2010
Comments
Post a Comment