ASP.NET FileUpload控件在Wizard控件内无法正常工作

时间:2022-07-19 03:33:56

I have a Wizard control with one of the pages containing a FileUpload control. I want to access the file stream at the point of the final page of the wizard but this doesn't seem to work.

我有一个向导控件,其中一个页面包含FileUpload控件。我想在向导的最后一页访问文件流,但这似乎不起作用。

As far as I can see, you can only access the file stream for the posted file on the postback which occurs immediately after the control has been used. As the file will ultimately be put into a DB record I could save it at this point, but I'd rather avoid this if possible.

据我所知,您只能在使用控件后立即发生的回发中访问已发布文件的文件流。由于文件最终将被放入DB记录中,我可以在此时保存它,但如果可能的话我宁愿避免这种情况。

Does anyone know of a workaround for this problem?

有谁知道这个问题的解决方法?

2 个解决方案

#1


I've not used this control myself but as it's based around the HTML standard INPUT control I think you are stuck with having to receive the file on the post-back that processes that control.

我自己没有使用过这个控件,但因为它基于HTML标准INPUT控件,我认为你不得不接收处理该控件的post-back上的文件。

The difficulty in circumventing this would be around how to pull the file from the client system when you are effectively sandboxed from the local filesystem, hence the need for the upload control.

避免这种情况的困难在于当你从本地文件系统有效地沙箱化时如何从客户端系统中提取文件,因此需要上传控制。

I would suggest that you store the file into your DB blob (or as a temp file on the filesystem, probably need a unique filename; I find a GUID works nicely) and then use the Session object to retain that reference to the end of the process. The only other alternative I can think of that doesn't involve major work would be to move the file upload to the last page of your wizard.

我建议你将文件存储到你的数据库blob中(或者作为文件系统上的临时文件,可能需要一个唯一的文件名;我发现GU​​ID很好用)然后使用Session对象来保留对该结尾的引用处理。我能想到的唯一另一个不涉及主要工作的替代方案是将文件上传移动到向导的最后一页。

#2


You could have the displaying of your individual wizard stages managed client-side using CSS/jQuery rather than keep POSTing back to the server? That way, your only POST (resulting in the upload) will be at the end of the Wizard.

你可以使用CSS / jQuery显示你的个人向导阶段在客户端管理,而不是保持POST回服务器?这样,您的唯一POST(导致上传)将在向导结束时。

#1


I've not used this control myself but as it's based around the HTML standard INPUT control I think you are stuck with having to receive the file on the post-back that processes that control.

我自己没有使用过这个控件,但因为它基于HTML标准INPUT控件,我认为你不得不接收处理该控件的post-back上的文件。

The difficulty in circumventing this would be around how to pull the file from the client system when you are effectively sandboxed from the local filesystem, hence the need for the upload control.

避免这种情况的困难在于当你从本地文件系统有效地沙箱化时如何从客户端系统中提取文件,因此需要上传控制。

I would suggest that you store the file into your DB blob (or as a temp file on the filesystem, probably need a unique filename; I find a GUID works nicely) and then use the Session object to retain that reference to the end of the process. The only other alternative I can think of that doesn't involve major work would be to move the file upload to the last page of your wizard.

我建议你将文件存储到你的数据库blob中(或者作为文件系统上的临时文件,可能需要一个唯一的文件名;我发现GU​​ID很好用)然后使用Session对象来保留对该结尾的引用处理。我能想到的唯一另一个不涉及主要工作的替代方案是将文件上传移动到向导的最后一页。

#2


You could have the displaying of your individual wizard stages managed client-side using CSS/jQuery rather than keep POSTing back to the server? That way, your only POST (resulting in the upload) will be at the end of the Wizard.

你可以使用CSS / jQuery显示你的个人向导阶段在客户端管理,而不是保持POST回服务器?这样,您的唯一POST(导致上传)将在向导结束时。