Mohammed Ehab
Mohammed Ehab

Reputation: 187

Is that possible to find a file in SharePoint site without specifying the drive contains it?

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

Answers (1)

Paul Schaeflein
Paul Schaeflein

Reputation: 627

Using Microsoft Graph, you search a drive

GET /sites/{site-id}/drive/root/search(q='{search-text}')

Upvotes: 1

Related Questions