Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have an issue where using the google calendar.
When I call the calendar Page, system throw the error "
"
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\inetpub\wwwroot\App_Data\client_secret.json'.


Please advice me

Thank you in advance

maideen

What I have tried:

<pre>Private Shared gFolder As String = System.Web.HttpContext.Current.Server.MapPath("/App_Data")

    Public Shared Function GetClientConfiguration() As GoogleClientSecrets
        Using stream = New FileStream(gFolder & "\client_secret.json", FileMode.Open, FileAccess.Read)
            Return GoogleClientSecrets.Load(stream)
        End Using
    End Function
Posted
Updated 7-Dec-18 4:03am
Comments
Mohibur Rashid 6-Dec-18 1:33am    
what does
> dir C:\inetpub\wwwroot\App_Data\client_secret.json
Says(in command prompt of course)

Try:
Private Shared gFolder As String = System.Web.HttpContext.Current.Server.MapPath("~/App_Data")
 
Share this answer
 
Comments
Richard Deeming 7-Dec-18 9:58am    
I'd be inclined to avoid HttpContext.Current in a static field initializer, since you can't control precisely when they will run. :)
Since you can't control precisely when a Shared field initializer runs, I'd be inclined to avoid using HttpContext.Current from one. If the class is initialized outside of a request context, you could end up with a NullReferenceException, which would then render your entire class unusable for the lifetime of your application.

Instead, map the path inside the method, and use an app-relative path as Solution 1 suggested:
Public Shared Function GetClientConfiguration() As GoogleClientSecrets
    Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
    If context Is Nothing Then Throw New InvalidOperationException("Cannot call this method outside of a request.")
    
    Dim filePath As String = context.Server.MapPath("~/App_Data/client_secret.json")
    Using stream = File.OpenRead(filePath)
        Return GoogleClientSecrets.Load(stream)
    End Using
End Function
 
Share this answer
 

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