Hi Expert,
I am trying to upload file to SharePoint using Plugin.
As I am uisng Dynamics V9 online so can not use the ("“Microsoft.SharePoint.Client.dll” and “Microsoft.SharePoint.Client.Runtime.dll”"). It gives System.Security.Permissions.EnvironmentPermission error and therefore this method probably does not support CRM Online.
So I trying do this with the help of REST
I followed the below url
https://mscrmsama.wordpress.com/2016/03/18/upload-a-file-to-sharepoint-2013-programmatically-externally/
But "getting forbidden url 403" at line
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
private static string GetFormDigestValue(string siteurl, NetworkCredential credentials)
{
string newFormDigest = “”;
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(siteurl + “/_api/contextinfo”);
endpointRequest.Method = “POST”;
endpointRequest.ContentLength = 0;
endpointRequest.Credentials = credentials;
endpointRequest.Accept = “application/json;odata=verbose”;
try
{
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
WebResponse webResp = endpointRequest.GetResponse();
Stream webStream = webResp.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
var j = JObject.Parse(response);
var jObj = (JObject)JsonConvert.DeserializeObject(response);
foreach (var item in jObj[“d”].Children())
{
newFormDigest = item.First()[“FormDigestValue”].ToString();
}
responseReader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return newFormDigest;
}
Thanks In Advanced
*This post is locked for comments