[Mono-list] response.writefile

Peter Hagen peter at wingsofdeath.net
Wed Mar 2 06:05:49 EST 2011


I have a issue with the Response.WriteFile(string filename) in the
HttpResponse, since I updated to 2.10.1. I use to add a full rooted path
to this method, without problems, but if I do that now, it will add my
application path to it. Looking at the code, I see there is a
GetNormalizedFileName, which checks nicely if its a windows path or an
unc path, but it wont check if its a unix path. I guess this is not
preferred behavior for Linux systems. 

This is what happens in my case: I call my download method with the
following path:


and then on Response.WriteFile() I get this exception:

[02-03-2011 11:48:25|7] ClientResponse.DownloadFile:Exception=Could not
find file
  at System.IO.FileInfo.get_Length () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileInfo:get_Length
  at System.Web.HttpResponse.WriteFile (System.String filename, Boolean
readIntoMemory) [0x00000] in <filename unknown>:0 
  at System.Web.HttpResponse.WriteFile (System.String filename)
[0x00000] in <filename unknown>:0 

/home/willowmedia/wingsofdeath/www is my application path in this case.
My solution is to check if the file exists in the normalize method:

                string GetNormalizedFileName (string fn)
                        if (String.IsNullOrEmpty (fn))
                                return fn;

                        if (File.Exists(fn))
                                return fn;

                        // On Linux we don't change \ to / since
filenames with \ are valid. We also
                        // don't remove drive: designator for the same
                        int len = fn.Length;
                        if (len >= 3 && fn [1] == ':' &&
IsFileSystemDirSeparator (fn [2]))
                                return Path.GetFullPath (fn); //
drive-qualified absolute file path

                        if (len >= 2 && IsFileSystemDirSeparator (fn
[0]) && IsFileSystemDirSeparator (fn [1]))
                                return Path.GetFullPath (fn); // UNC

                        HttpContext ctx = context ??
                        HttpRequest req = ctx != null ? ctx.Request :

                        if (req != null)
                                return req.MapPath (fn);

                        return fn; // Or should we rather throw?

But I'm not sure if that would be a solution for everyone. If I would
want to report a bug on it, in which product should this be added?
'Mono: Class libraries'?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20110302/5c6b940a/attachment.html 

More information about the Mono-list mailing list