如何从FileUploader绑定GridView中的文件并将文件保存到该GridView的文件夹中。 [英] How to bind files in GridView from FileUploader and Saving files into a folder from that GridView.

查看:111
本文介绍了如何从FileUploader绑定GridView中的文件并将文件保存到该GridView的文件夹中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



请帮我解决这个问题。我在WebForm中有一个FileUploader,Attach Button,Done Button,Remarks Textbox和GridView。 gridview的文件上传和绑定工作正常。



1-我想在gridview的第二列上传文件。其他列用于备注和日期文本框。



2-上传完成后。我想将在GridView中上传的文件保存到项目文件夹中的文件夹中。



3-我想保存路径,文件名,备注文本,日期文本某处(这是一个大问题)因此我可以在以后将该信息插入数据库时​​检索该信息(页面重定向其他页面)。



谢谢。



这是我的代码..



Dear All,

Please help me in this issue. I have a FileUploader, Attach Button, Done Button, Remarks Textbox and GridView in a WebForm. Fileuploading and Binding of gridview is working fine.

1- I want to upload files in the gridview's 2nd Column. the other columns are for remarks and date textboxes.

2- After upload completes. I want to save that files, uploaded in GridView, into a folder present in my project folder.

3- I want to save PATH, FILE NAME, REMARKS TEXT, DATE TEXT somewhere(THATS THE BIG PROBLEM) so I can retrieve that information later(PAGE REDIRECTING TO OTHER PAGE) when I have to insert that information into Database.

Thanks.

here is my code..

public partial class Attachments_AccountClosing : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TaskNo_Lbl.Text = Request.QueryString.Get("taskNo").ToString();
    }
    protected void Done_Btn_Click(object sender, EventArgs e)
    {
        Response.Redirect("Account_Closing.aspx?attachments=1");
    }
    protected void Attach_Btn_Click(object sender, EventArgs e)
    {
        string Extension = Path.GetExtension(FileUploader_Att.PostedFile.FileName);
        string[] validFileTypes = { ".xlsx", ".xls", ".doc", ".txt"};
        bool isValidFile = false;
        for (int i = 0; i < validFileTypes.Length; i++)
        {
            if (Extension == validFileTypes[i])
            {
                isValidFile = true;
                break;
            }
        }
        if (!isValidFile)
        {
            Lbl_Notify.ForeColor = System.Drawing.Color.Red;
            Lbl_Notify.Text = "Invalid File. Please upload a File with valid extension ";
        }
        else
        {
            if (FileUploader_Att.HasFile)
            {
                BindData();
                Lbl_Notify.ForeColor = System.Drawing.Color.Green;
                Lbl_Notify.Text = "File uploaded successfully.";
            }
        }
        
    }

    private void BindData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Sr.No");
        dt.Columns.Add("File_");
        dt.Columns.Add("AddedBy_");
        dt.Columns.Add("Remarks_");
        dt.Columns.Add("Date_");
        foreach (GridViewRow gvRow in Attachments_GV.Rows)
        {
            Label File_ = gvRow.FindControl("Label1") as Label;
            Label AddedBy_ = gvRow.FindControl("Label2") as Label;
            Label Remark_ = gvRow.FindControl("Label3") as Label;
            Label Date_ = gvRow.FindControl("Label4") as Label;
            dt.Rows.Add();
            dt.Rows[dt.Rows.Count - 1][0] = gvRow.Cells[0].Text;
            dt.Rows[dt.Rows.Count - 1][1] = File_.Text;
            dt.Rows[dt.Rows.Count - 1][2] = AddedBy_.Text;
            dt.Rows[dt.Rows.Count - 1][3] = Remark_.Text;
            dt.Rows[dt.Rows.Count - 1][4] = Date_.Text;
        }
      
        dt.Rows[dt.Rows.Count - 1][1] = FileUploader_Att.FileName;
        dt.Rows[dt.Rows.Count - 1][2] = Session["empcode"].ToString();
        dt.Rows[dt.Rows.Count - 1][3] = Remarks_text.Text;
        dt.Rows[dt.Rows.Count - 1][4] = DateTime.Now.ToString("dd-MMM-yyyy HH:m:ss");
        Session["AttachedFiles"] = dt;
        Attachments_GV.DataSource = Session["AttachedFiles"] as DataTable;
        Attachments_GV.DataBind();
    }

}

推荐答案

您是否找到了此问题的解决方案?我有同样的问题。如果您有解决方案,请帮我解决
Did you find solution for this problem? i have same issue. Please help me out if you had a solution for this


这篇关于如何从FileUploader绑定GridView中的文件并将文件保存到该GridView的文件夹中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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