c# - Uploading a file to sharepoint without a password -


i trying upload file sharepoint c# using microsoft sharepoint client

i have no issues when create context , give username , password this

                using (clientcontext ctx = new clientcontext(spsite))                 {                      if (!system.io.file.exists(filelocation))                         throw new filenotfoundexception("file not found.", filelocation);                      var credentials = new networkcredential("username", "password");                     ctx.credentials = credentials;                     web web = ctx.web;                      ctx.load(user);                     ctx.executequery();                     string filename = system.io.path.getfilename(filelocation);                     filestream filestream = system.io.file.openread(filelocation);                      ctx.load(web.folders);                     ctx.executequery();                     folder spfolder = web.folders.firstordefault(x => x.name.equals(splistcleanname));                      filecreationinformation fci = new filecreationinformation();                     fci.url = spsite + splibraryname + file;                        byte[] bytes = system.io.file.readallbytes(filelocation);                     fci.content = bytes;                      microsoft.sharepoint.client.file spfile = spfolder.files.add(fci);                     spfile.listitemallfields.update();                     ctx.executequery();                  } 

but issue comes in network credentials part. there way use current users credentials (through iis or .net or anything) don't have ask password? since isn't want save in plain text anywhere.

thank in advance

use credentialcache.defaultcredentials (https://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultcredentials(v=vs.110).aspx) instead of networkcredential object.

this use users security context.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -