用FileInput控件,搜索一下,例子很多

解决方案 »

  1.   

    1.弹出对话框的代码<Input Type="File" id="FileUp" runat="server" size="20"><br/>If FileUp.PostedFile.ContentLength = 0 Then
    FileInfo.Visible = False
    Exit Sub
    Else
    FileInfo.Visible = True
    FDisplay1.Visible = True
    End IfFSize.Text ="上传文件大小"+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB"
      

  2.   

    //将图片保存到目录CompImage下
    string strFile = fImage.PostedFile.FileName.Trim();
    strFile = System.IO.Path.GetFileName(strFile);
    string strPath = Server.MapPath("../CompImage/");
    string strPathFile = strPath.Trim() + strFile.Trim();
    fImage.PostedFile.SaveAs(strPathFile);
      

  3.   

    //上传页面
    IOAction.FileAction.SavePostedFileToExsistDirectory( System.Web.HttpContext.Current.Server.MapPath("upload\\"))//自定义类
    namespace IOAction
    {
    /// <summary>
    /// 自定义的文件操作类
    /// </summary>
    public class FileAction
    {
    public FileAction()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    } //把上传文件存入已存在路径
    public static string SavePostedFileToExsistDirectory(string pathtosave, System.Web.HttpPostedFile postedfile, bool overwrite)
    {
    string savedFileName = pathtosave + System.IO.Path.GetFileName(postedfile.FileName.Trim()); if (overwrite)
    {
    postedfile.SaveAs(savedFileName);
    }
    else
    {
    int fileSuffix = 1;
    while(File.Exists(savedFileName))
    {
    savedFileName = Path.Combine(pathtosave, Path.GetFileNameWithoutExtension(postedfile.FileName) + "[" + fileSuffix + "]" + Path.GetExtension(postedfile.FileName));
    fileSuffix ++;
    }
    postedfile.SaveAs(savedFileName);
    } return savedFileName; }
    }
    }
      

  4.   

    <form id="FilesAdd" method="post" encType="multipart/form-data" runat="server"><INPUT type="file" id="file1" runat="server">保存时file.PostedFile.SaveAs(strPath);
      

  5.   

    对不起,我上面写的那句调用贴错了,应该是:IOAction.FileAction.SavePostedFileToExsistDirectory( System.Web.HttpContext.Current.Server.MapPath("upload\\, this.file1.PostedFile, this.CheckBox1.Checked);