首页 新闻 会员 周边

FileUpload问题

0
悬赏园豆:100 [已解决问题] 解决于 2013-10-25 16:03

我在vs里面测试上传文件和发布在本地iis上面上传文件都没问题  但发布到客户服务器iis上面就报错了

Server Error in '/' Application.


 

Could not find file 'c:\windows\system32\inetsrv\help-03.jpg'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\help-03.jpg'.
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\help-03.jpg'.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +9727023
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +1142
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) +84
   ExtJsTreeWcf.Registration.IsAllowedExtension(FileUpload hifile) in D:\桌面\乾元易农\WebApplication\Registration.aspx.cs:43
   ExtJsTreeWcf.Registration.btnsubmit_Click(Object sender, EventArgs e) in D:\桌面\乾元易农\WebApplication\Registration.aspx.cs:105
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

'c:\windows\system32\inetsrv\  这个地址是客户服务器上iis的地址

求解决

问题补充:
public static bool IsAllowedExtension(FileUpload hifile)
        {
            System.IO.FileStream fs = new System.IO.FileStream(hifile.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
            string fileclass = "";
            //这里的位长要具体判断.
            byte buffer;
            try
            {
                buffer = r.ReadByte();
                fileclass = buffer.ToString();
                buffer = r.ReadByte();
                fileclass += buffer.ToString();
            }
            catch
            {
            }
            r.Close();
            fs.Close();
            if (fileclass == "255216" || fileclass == "7173" || fileclass == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
            {
                return true;
            }
            else
            {
                return false;
            }
        }

我发现了一个问题  我后台没有加这个判断 上传文件可以成功的 

前台就是加了这个判断  我估计hifile.PostedFile.FileName和这个有关

TimelessMe的主页 TimelessMe | 初学一级 | 园豆:94
提问于:2013-10-25 14:45
< >
分享
最佳答案
0

在你的机器复制张help-03.jpg图片 到客户机器的 c:\windows\system32\inetsrv\ 目录下试试

收获园豆:100
Yu | 专家六级 |园豆:12980 | 2013-10-25 14:51

成功了- -  怎么回事?

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 14:57

@TimelessMe: 

报错写着的

Could not find file 'c:\windows\system32\inetsrv\help-03.jpg'

Yu | 园豆:12980 (专家六级) | 2013-10-25 14:58

是不是路径没取对  但是我本地iis和vs里面都可以

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 14:58

@TimelessMe: 这跟你的程序是没关系的

Yu | 园豆:12980 (专家六级) | 2013-10-25 14:59

@Yu: 那是怎么回事?

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:00

@Yu: 要配置iis么?

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:02

@TimelessMe: help-03.jpg 是你上传的吗,如果是 那配置保存的路径就有问题了

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:05

@Yu: 或者说 保存和读取的路径不一致

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:08

@Yu: 那怎么弄  我是本地访问客户服务器网站的

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:09

@Yu: 那怎么弄  我是本地访问客户服务器网站的

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:09

@TimelessMe: 那 help-03.jpg 是不是你上传的?

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:11

@Yu: 是 是我从我本地访问客户服务器上传的

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:13

@TimelessMe: 那上传保存的路径 有没有这个文件

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:14

@Yu: 我本地有  服务器上没 

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:15

@TimelessMe: 你现在是从本地上传文件到服务器, 如果你执行了上传操作,而服务器上没有收到,那就是你程序的问题了

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:17

@Yu: 就是不知道问题出在哪- -  搞了好久了

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:18

@Yu: 由于服务器没收到,所以读取时,就是报上面的错了。还有这个读取的路径也是有问题的,你不能把文件保存在服务器上的系统文件夹里面,所以还要查查你的路径配置有没有问题

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:20

@Yu: 路径配置怎么查 ?

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:21

@Yu: 我补充了下问题  你看下

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:24

@TimelessMe: 查查代码里面 实现保存的代码,看看保存路径怎么来的,你就怎么修改 通常

string fullname=Server.MapPath("~\SavePath\")+filename;

具体看你怎么实现了

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:26

@Yu: 是这样保存的

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 15:26

@TimelessMe: 你说的前台,是怎么实现的

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:31

@Yu: 如果是这个IsAllowedExtension 的问题 , 你就在最前面加一个判断

if(!File.Exists(hifile.PostedFile.FileName))return false;

Yu | 园豆:12980 (专家六级) | 2013-10-25 15:37

@Yu: 就是IsAllowedExtension的问题   我去掉了 直接判断后缀名  现在正常了  谢谢回答^_^

TimelessMe | 园豆:94 (初学一级) | 2013-10-25 16:02
其他回答(1)
0

System.IO.Stream myStream;
Int32 fileLen;
fileLen = FileUpload1.PostedFile.ContentLength;
Byte[] content = new Byte[fileLen];
myStream = FileUpload1.FileContent;
myStream.Read(content, 0, fileLen);
myStream.Close();

这样写就没问题了!

天仁 | 园豆:202 (菜鸟二级) | 2016-05-17 09:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册