PSS ID Number: 172551
Article Last Modified on 3/7/2005
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q172551
SYMPTOMS
CInternetSession::OpenURL() fails if you use a URL that specifies a file that contains spaces or other unsafe characters. For example, the following will fail:
CMyInternetSession s(""); CStdioFile* p = s.OpenURL("file://c:/temp/Text Document.txt");
As a result, a File Exception is thrown and the following message appears:
c:/temp/Text%20Document.txt was not found.
CAUSE
The specifications for a URL designate certain characters that must be escaped when they are present in a URL. The space character is one of the characters that must be escaped.
The function
CInternetSession::OpenURL() calls a function that converts unsafe characters in the URL to their escape sequences before processing the URL further. If the URL is using the file protocol it creates a CStdioFile and returns a pointer to this object. However, CStdioFile does not understand the escaped path and, as a result, an exception is thrown.
RESOLUTION
When you use the file protocol, you must not convert unsafe characters to their escape sequences. The following code demonstrates how to do this by writing a
CInternetSession derived class to override OpenURL().