在ASP.NET文件上传控制 [英] File upload control in ASP.NET

查看:101
本文介绍了在ASP.NET文件上传控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用文件上传控制在ASP.NET中上传图片。
在我的形式有两种buttons.one分配其重定向到其它形式和其他提交表单的标准。
后分配的标准只有用户具有使用提交按钮。

我的问题是正在上传图片,并点击按钮AssignCriteria并返回到原来的页面时,上载控制越来越空。
如何保持这种上传图片的控制值在文本框即使我们重定向到其他页面,然后回来。


解决方案

 < ASP:文件上传=服务器ID =uploadStatement/>
< ASP:按钮=服务器文本=上传的OnClick =cmdUpload_Click/>

下一步code选择的文件到临时文件夹在服务器上上传,在我的情况 - 解析它并删除文件

 保护无效cmdUpload_Click(对象发件人,EventArgs的发送)
    {
        变种文件名=使用Server.Mappath(Path.Combine(TEMP,String.Concat(Guid.NewGuid()的ToString(),Path.GetExtension(uploadStatement.FileName))));
        尝试
        {
            uploadStatement.SaveAs(文件名);            //解析文件
        }
        最后
        {
            File.Delete(文件名);
        }
    }

i am using file upload control in ASP.NET for uploading images. In my form there are two buttons.one for assigning criteria which redirects to other form and other for submitting form. After assigning criteria only the user has to use submit button.

My problem is when is upload image and click on AssignCriteria button and return back to original page,the upload control is getting blank. How to keep that upload image control value in that textbox even if we redirected to other page and come back.

解决方案

<asp:FileUpload runat="server" ID="uploadStatement" />
<asp:Button runat="server" Text="Upload" OnClick="cmdUpload_Click" />

Next code uploads selected file to Temp folder on the server, in my case - parses it and deletes the file.

    protected void cmdUpload_Click(object sender, EventArgs e)
    {
        var fileName = Server.MapPath(Path.Combine("Temp", String.Concat(Guid.NewGuid().ToString(), Path.GetExtension(uploadStatement.FileName))));
        try
        {
            uploadStatement.SaveAs(fileName);

            // parse file
        }
        finally
        {
            File.Delete(fileName);
        }
    }

这篇关于在ASP.NET文件上传控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆