开发者

access HttpPostedFile without saving, get error "Request for the permission of type 'System.Security.Permissions.FileIOPermission..."

Can we access HttpPostedFile's uploaded file without saving the file. I am trying to read file's name and size but get error "Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e0开发者_JAVA技巧89' failed."

It works well on local host but this error accure on shared hosting server (GoDaddy). Please guide me a solution. I need to read some properties of files before saving it.

Thanks


You can read the file into a byte stream and then feed the byte stream into a FileInfo class. But permissions may be preventing you from even reading the byte stream if Asp.Net does not have write access to the temp directory. Could we see the code that throws the error?

Edit

I was wrong on the reading into a FileInfo class. That will work if the file is physically pointed to on the server. You should be able to get the filename of the file by call .FileName on the Request.Files[0] of the posted request. If you wanted to read that into memory, it would look something like this:

 byte[] fileData = null; 
 using (var binaryReader = new BinaryReader(Request.Files[0].InputStream)) { fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength); }

Have you tried just looking at Request.Files[0].FileName to see if that returns the correct filename you were looking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜