Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to load my slider of image which image comes from google drive or one drive. i used below code for google drive but it returns all the files and i want to get from specific folder.
C#
GoogleConnect.ClientId = "xxxxxx";
GoogleConnect.ClientSecret = "xxxxxx";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
GoogleConnect.API = EnumAPI.Drive;
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
    string code = Request.QueryString["code"];
    string json = GoogleConnect.Fetch("me", code);
    GoogleDriveFiles files = new JavaScriptSerializer().Deserialize<GoogleDriveFiles>(json); // This will returns the files      
}
else if (Request.QueryString["error"] == "access_denied")
{
    ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
Posted
Updated 16-Jun-16 2:04am
v2

excellent tutorial here:

http://www.daimto.com/google-drive-api-c/[^]
 
Share this answer
 
Comments
MiteshMachhi 16-Jun-16 7:22am    
i refer this site but it gives all the files & directories.
El_Codero 16-Jun-16 7:35am    
"if Search is null will return all files". Do you use the search in your request? In google drive, a folder is like a file, so using the search with your specific file (=folder) should return the list of child files (files within your specific folder). https://developers.google.com/drive/v3/web/folder
MiteshMachhi 16-Jun-16 8:42am    
where i set the search criteria in above condition.
try this

C#
Private Sub GetFileList(ParentFolder As String)

    Authorize() 'Take care of authorization... you could use JS to ask the user and get the Auth Token

    'MSO - 20130423 - Search the Google Drive File with the specified foldername
    'Create the search request
    Dim oListReq As Google.Apis.Drive.v2.FilesResource.ListRequest
    Dim oFileList As FileList
    'mimeType = 'application/vnd.google-apps.folder'

    oListReq = oDriveService.Files.List()
    'Search for a specific file name
    oListReq.Q = "mimeType = 'application/vnd.google-apps.folder' and title = '" + ParentFolder + "' and trashed=false"
    oListReq.Fields = "items/id" 'MSO - 20130621 - only ID needed for next query
    oListReq.MaxResults = 10 'Max 10 files (too may I Expect only 1)

    'Get the results
    oFileList = oListReq.Fetch()

    'Only 1 result is expected
    If oFileList.Items.Count = 1 Then
        Dim oFile As File = oFileList.Items(0)
        FolderId = oFile.Id 'Get FolderId
    End If

    oListReq = oDriveService.Files.List()
    'Search for a specific file name in the folder
    oListReq.Q = "'" + FolderId + "' in parents and trashed=false "
    'oListReq.Fields = "items(id,alternateLink)" 'MSO - 20130621 - Optimize your query if you need only certain fields

    'Get the results
    oFileList = oListReq.Fetch()

    'TODO: oFileList now have the list of the files in the folder, but there could me more "pages"

End Sub
 
Share this answer
 
v2
Comments
MiteshMachhi 16-Jun-16 7:30am    
same as above link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900