I am trying to download a file from dropbox using the RESTful API. When I encounter a file that has a space in it “My Photo.png” the program stops on var request = (HttpWebRequest) WebRequest.Create(requestUri); It returns a 403 error. If I remove the spaces and try the file download again it works perfectly. Ive checked the formatted uri and it is being returned as “My+Photo.png” is this how it should be? What am I doing wrong?
var uri = new Uri(new Uri(DropboxRestApi.ApiContentServer),
String.Format("files?root={0}&path={1}",
root, UpperCaseUrlEncode(path)));
My Method:
private static string UpperCaseUrlEncode(string s)
{
char[] temp = HttpUtility.UrlEncode(s).ToCharArray();
for (int i = 0; i < temp.Length - 2; i++)
{
if (temp[i] == '%')
{
temp[i + 1] = char.ToUpper(temp[i + 1]);
temp[i + 2] = char.ToUpper(temp[i + 2]);
}
}
return new string(temp);
}
Could you do the normal URLEncode and do a string.Replace on the temp string it will work perfect for files with a space in the file name