Today I got a requirement to read a document inside a folder. I have integrated CRM with SharePoint and once we upload a document, list component creates a folder with the title appended with GUID of the record and places the files inside.
Here is the code to read the files from that folder.
{
clientContext.Credentials = new System.Net.NetworkCredential(SharepointUsername, Sharepointpassword, “”);
Web objWeb = clientContext.Web;
List douLib = objWeb.Lists.GetByTitle(“Case”);
clientContext.Load(objWeb);
CamlQuery caml = new CamlQuery();
string strQuery = ” “ +
“” +
“” +
“” +
“” +
“” +
“” +
“” +
“” +
“”;
caml.ViewXml = strQuery;
ListItemCollection items = douLib.GetItems(caml);
clientContext.Load(items);
clientContext.ExecuteQuery();
WebRequest objWebRequest;
MemoryStream objMemStream;
WebResponse objResponse;
Stream fileStream;
for (int intCount = 0; intCount < items.Count; intCount++)
{
// Get the path of
objWebRequest = WebRequest.Create(new Uri(“”));
objWebRequest.Credentials = new System.Net.NetworkCredential(SharepointUsername, Sharepointpassword, “”);
objMemStream = new MemoryStream();
try
{
objResponse = objWebRequest.GetResponse();
fileStream = objResponse.GetResponseStream() as Stream;
fileStream.CopyTo(objMemStream);
objMemStream.Position = 0;
byte[] objByteArray = objMemStream.ToArray();
// System.IO.File.WriteAllBytes(@”\test.xlsx”, objByteArray);
}
catch (Exception ex)
{
throw ex;
}
}
}
—
Happy CRM’ing
Gopinath.
Hello Gopinath, I really liked your post, can you tell me how do we need to retrieve the CRM Documents from Sharepoint site ?
LikeLike