Reputation: 187
I'm now getting a file from specific drive on SharePoint,but the customer asked to search for the file without specifying a drive.
public static byte[] SharePointDownload(string token, string fileName, string sharepointTargetLibrary)
{
string baseSiteId = GetSiteId(token);
string folderId;
if (string.IsNullOrEmpty(baseSiteId))
{
return null;
}
else
{
folderId = GetFolderId(token, baseSiteId, sharepointTargetLibrary);
if (string.IsNullOrEmpty(folderId))
{
return null;
}
}
try
{
WebClient wc = new WebClient();
byte[] result;
wc.Headers[HttpRequestHeader.Authorization] = "Bearer " + token;
wc.Headers[HttpRequestHeader.Accept] = "application/json";
result = wc.DownloadData(string.Format(@"https://graph.microsoft.com/v1.0/sites/{0}/drives/{1}/root:/{2}:/content", baseSiteId, folderId, fileName));
wc.Dispose();
if (result.Length>0)
{
return result;
}
else
{
return null;
}
}
catch (Exception ex)
{
LoggerHelper.Log(ex.Message);
return null;
}
}
now i want to know if this line
result=wc.DownloadData(string.Format(@"https://graph.microsoft.com/v1.0/sites/{0}/drives/{1}/root:/{2}:/content", baseSiteId, folderId, fileName));
can get rid of folderId
and searches with the fileName
only specified
Upvotes: 0
Views: 45
Reputation: 627
Using Microsoft Graph, you search a drive
GET /sites/{site-id}/drive/root/search(q='{search-text}')
Upvotes: 1