Fix 401 Unauthorized Exception uploading file to SharePoint 2010

I have a WCF service hosted in IIS on Domain 1. This service is accepting a request to upload a file, and then uploading the file to a SharePoint 2010 Server on Domain 2, using the client object model.

Everything works fine when I hardcode the username, password & domain using:

context.Credentials = new NetworkCredential(login, password, domain); 

However, due to the compliance & security we cannot do this in our company. We need to use integrated security if possible. I have tried setting the credentials to both

context.Credentials = CredentialCache.DefaultCredentials; context.Credentials = CredentialCache.DefaultNetworkCredentials; 

But neither appear to work, we receive the error

System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

Can someone provide any tips on how to fix this? Or tips that might lead us to the resolution, logs to check etc. I am not the developer of the SharePoint site, but can chase them down. I have gone through many questions/answers here and none seem to help us.

Fix 401 Unauthorized Exception uploading file to SharePoint 2010

I have a WCF service hosted in IIS on Domain 1. This service is accepting a request to upload a file, and then uploading the file to a SharePoint 2010 Server on Domain 2, using the client object model.

Everything works fine when I hardcode the username, password & domain using:

context.Credentials = new NetworkCredential(login, password, domain); 

However, due to the compliance & security we cannot do this in our company. We need to use integrated security if possible. I have tried setting the credentials to both

context.Credentials = CredentialCache.DefaultCredentials; context.Credentials = CredentialCache.DefaultNetworkCredentials; 

But neither appear to work, we receive the error

System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

Can someone provide any tips on how to fix this? Or tips that might lead us to the resolution, logs to check etc. I am not the developer of the SharePoint site, but can chase them down. I have gone through many questions/answers here and none seem to help us.

Need permissions uploading .aspx page to my own sharepoint site

When I try uploading a .aspx to the “pages” library on my own sharepoint site, I get this message:

Sorry, you don’t have access to this page Awaiting approval. We’ll let you know about any updates. (send a message to request permission)

It is incredibly frustrating. I’ve sent myself a message asking myself to give myself permissions, but I can’t see this request anywhere, or the option to give myself permissions. I already have “full control” from what I can see.

My ultimate goal is to serve a react single-page-application within sharepoint. That’s another can of worms. I just renamed the index.html from the bundle to .aspx, and plan to upload my js/css/images to the pages library as well. I’d love a less nonsensical solution to deploying my app if anyone knows 🙂 Thank you

Bad Request 400 when uploading file to Sharepoint Online document library

I am trying to upload a file to a document library and keep getting a statusCode of 400 with the text just saying “Bad Request.” I was rifling through some other forums and saw that the API could potentially not have the right permissions but I haven’t been able to figure out how to even check that, let alone set it to have full control.

Additionally, the site where the document library lives is a subsite, so I’m not sure if that has an effect on what I’m trying to do but I haven’t seen an example where the library lives in a subsite to know if it does affect anything.

Here is my code, site name removed for client privacy, (largely taken from this post):

function dofunc() {     var control = document.getElementById("elementIDHere");     control.addEventListener("change", fdocattach, false); }  var file; var contents;  function fdocattach(event) {     var i = 0,     files = event.srcElement.files,     len = files.length;      for (; i < len; i++) {         console.log("Filename: " + files[i].name);         console.log("Type: " + files[i].type);         console.log("Size: " + files[i].size + " bytes");     }      if (!window.FileReader) {         alert("The FileSystem APIs are not fully supported in this browser.");         return false;     }                 if (files.length > 0) {         file = files[0];         fileName = file.name;          var reader = new FileReader();         reader.onload = fonload;          reader.onerror = function(event) {             console.error("File reading error " + event.target.error.code);         };         reader.readAsArrayBuffer(file);     }            return false; }  function _arrayBufferToBase64(buffer) {     var binary = ''     var bytes = new Uint8Array(buffer)     var len = bytes.byteLength;     for (var i = 0; i < len; i++) {         binary += String.fromCharCode(bytes[i])     }     return binary;  }  function fonload(event) {     contents = event.target.result;             $  .getScript("sitename/subsite/_layouts/15/SP.RequestExecutor.js", fonload2); }  function fonload2() {     var contents2 = _arrayBufferToBase64(contents);      var createitem = new SP.RequestExecutor("sitename/subsite");     createitem.executeAsync({         url: "sitename/subsite/_api/web/GetFileByServerRelativeUrl('/documentLibraryName')/Files/add(url='" + file.name + "',overwrite=true)",         method: "POST",         binaryStringRequestBody: true,         body: contents2,         success:  fsucc,         error: ferr         state: "Update"     });      function fsucc(data)     {         alert('success');     }            function ferr(data)     {         alert('error\n\n' + data.statusText + "\n\n" + data.responseText);     }        } 

The remote server returned an error: (401) Unauthorized: While uploading file in document library using App Based Token Authentication

I am trying to upload a document to the document library using App Based Token authentication in SharePoint Online.

I have referred following link to set up the App Based token and the token successfull worked when I try to read any thing from the site.

But when I try to upload a file using following code,

string file = @"Path Of the file"; System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read); using (var ctx = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "CLIENTID","CLIENTSECRET")) {     try     {         ctx.Load(ctx.Web, p => p.Title);                      ctx.ExecuteQuery();                         Console.WriteLine(ctx.Web.Title);                      Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, "RelativePathToDocumentLibrary" + "/test.docx", fs, false);                 }                 catch (Exception ex)                 {                 } } 

It gives me error of

{“The remote server returned an error: (401) Unauthorized.”}

Any suggestion or reference link is most welcome.

uploading a file to sharepoint using your phpSPO library

I saw from one of your previous post that you are an author of phpSPO. I came across your phpSPO library earlier this month while trying to access sharepoint by php.

I went through your GitHub and saw the samples but with my limited knowledge on sharepoint, I only manage to get myself authenticated with sharepoint using my account, but I don’t know how to say upload a file into sharepoint.

are you able to give me a simple example how to upload a file into sharepoint using your phpSPO library?

Error while uploading password protected file in IRM Enabled library

I am trying to upload a password protected PDF file in a document library which is IRM enabled and while uploading the file I am getting below error.

The PDF document you tried to upload was not encrypted in SharePoint therefore it cannot be uploaded to this library.

Is there any link which says that password protected documents are not allowed in IRM enabled document library.

Error in Uploading Image using REST API in Magento 2

I am getting below error while hit REST API from postman:

“message”: “The product can’t be saved.”,

I have used below details for API:

URL: magento.localhost/rest/V1/products/p1/media

HEADERS :

Content-Type:application/json

Authorization:Bearer 1si2ch4k8to78ytx14is8gcgfs4p3glk

BODY

{      "entry":{         "id":153,       "media_type":"image",       "label":"test",       "position":0,       "disabled":true,       "types":[            "image"       ],       "file":"test.png",       "content":{            "base64_encoded_data":"base64_encoded_data",          "type":"image/png",          "name":"new image"       }    } } 

Can anyone please help me in this? I tried lot of thing but nothing is working.