问题~~上传文件后怎么判断~是否上传完毕?并显示以上传的文件

解决方案 »

  1.   

    可以在上传处理的代码最后输出前台脚本来弹出个提示窗 (alert("文件上传完毕!"))
    同样地,直接显示文件名加链接即可显示文件。
      

  2.   

    if(!this.IsClientScriptBlockRegistered("loadUploadFileScript"))
    this.RegisterClientScriptBlock("loadUploadFileScript",GetScriptStr(Request.QueryString["method"],ubbStr));
      

  3.   

    private string GetScriptStr(string method,string text)
    {
    return @"
    <script language=javascript>
    parent." + method + @"('" + text + @"');
    alert(""上传完成!"");
    </script>
    ";
    }
      

  4.   

    private void btnUpload_Click(object sender, System.EventArgs e)
    {
    //遍历File表单元素
    HttpFileCollection files  = HttpContext.Current.Request.Files;
    DateTime dt=DateTime.Now;
    string strPath=System.Configuration.ConfigurationSettings.AppSettings["uploadpath"].ToString();
    try
    {
    for(int iFile = 0; iFile < files.Count; iFile++)
    {
    HttpPostedFile postedFile = files[iFile];
    string fileName,linkName;
    fileName = System.IO.Path.GetFileName(postedFile.FileName);
    if (fileName != "")
    {
    // System.IO.Stream imgdatastream = postedFile.InputStream; 
    // int imgdatalen = postedFile.ContentLength;
    // byte[] imgdata = new byte[imgdatalen]; 
    // int n = imgdatastream.Read(imgdata,0,imgdatalen);
    DataTable tmpDt=(DataTable)ViewState["filesDt"];
    DataRow dr=tmpDt.NewRow();
    dr[0]=fileName;
    dr[1]=Session["ID"].ToString()+"_"+dt.Year+dt.Month+dt.Day+dt.Hour+dt.Minute+dt.Second+System.IO.Path.GetExtension(fileName);
    linkName=dr[1].ToString();

    tmpDt.Rows.Add(dr);
    ViewState["filesDt"]=tmpDt; //实现上传
    string pathStr=strPath+linkName;
    if (System.IO.Directory.Exists(strPath))
    {
    postedFile.SaveAs(pathStr);
    }
    else
    {
    System.IO.Directory.CreateDirectory(strPath);
    postedFile.SaveAs(pathStr);
    }

    // this.fileName.Value+=fileName+";";
    // this.linkName.Value+=linkName+";";
    //邦定文件列表
    this.binderDrgFiles();
    WebCommon.ShowMsg(this,"附件上传成功");

    }
    else
    WebCommon.ShowMsg(this,"请选择要上传的文件");

    }
    }
    catch(Exception err)
    {
    WebCommon.ShowMsg(this,err.Message);
    }
    }
      

  5.   

    我用的上传代码是这样的要怎么改啊?
     Dim filesplit() As String = Split(File1.PostedFile.FileName, "\")
                    Dim filename As String = filesplit(filesplit.Length - 1)
                    File1.PostedFile.SaveAs("D:\wwwroot\WebService1\QZzhonghang" & "\" & Year(Now()) & Month(Now()) & Day(Now()) & filename)
                    DIV1.InnerHtml = "文件名称:" & File1.PostedFile.FileName & "<br>" & _
                  "文件类型:" & File1.PostedFile.ContentType & "<br>" & _
                  "文件大小:" & File1.PostedFile.ContentLength