Problem using webclient : (illegal characters in Path) error

Kiran Beladiya

New member
Joined
Dec 22, 2006
Messages
4
Programming Experience
1-3
I am facing problem while making web request by WebClient.
I am making request to google map geocode apge to findout the longitude and latitude of particular address.
Here is my code to do that :


Dim QueryString As String
Dim responseText As String = ""
Dim WC As New Net.WebClient
Dim SR As IO.StreamReader

QueryString = "?q=" & getValidAddressString() & "&output=csv&key=" & ConfigurationManager.AppSettings("GeoCodeKey")

Dim redirectURL As String = ConfigurationManager.AppSettings("GeoCodeURL") & QueryString

SR = New IO.StreamReader(WC.OpenRead(redirectURL))
responseText = SR.ReadToEnd()

SR.Close()
processResponseText(responseText)


The strange thing is that for same address string, the code is working without any problem in one page. While the same code(have copy pasted) in another page is throwing the following error :

Illegal characters in path.
Exception Details: System.ArgumentException

at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.Path.GetFullPath(String path)
at System.Net.WebClient.GetUri(String path)
at System.Net.WebClient.DownloadData(String address)
at KG.GeoCodeHelper.Page_Load(Object sender, EventArgs e) in
 
Is it possible that the configuration is not being read properly in the other page? Meaning there is no web.config in the other project or the key does not exist in the other project, or the value contains some bad characters in the other config. That is the only place I could see that coming from. Possibly try debugging or displaying the contents of the variable you are using upon exception.
 
Back
Top