如题!!高手请多多指教!

解决方案 »

  1.   

    http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.html
    http://www.csharphelp.com/archives2/archive335.html
      

  2.   

    首先要把file field变成server控件
    protected System.Web.UI.HtmlControls.HtmlInputFile File1;
    然后private void Button1_Click(object sender, System.EventArgs e)
    {
    if (File1.PostedFile!=null)
    {
    string filename=DateTime.Now.Date.ToString("yyyymmdd")+DateTime.Now.ToLongTimeString().Replace(":","")+rd.Next(9999).ToString()+".xls";
    File1.PostedFile.SaveAs(@Server.MapPath("file/")+filename);
    }
    }
      

  3.   

    string FileN=file.PostedFile.FileName.Trim();
    if(FileN!="")
    {
       try
    {
    string oldName=FileN.Substring(FileN.LastIndexOf("\\") + 1);//文件的原名
    string formart=oldName.Substring(oldName.LastIndexOf("."));//取得文件格式
    string date=DateTime.Now.ToShortDateString().Replace("-", "_");
    string time=DateTime.Now.ToLongTimeString().Replace(":", "_");
    string newName="Y1_"+yearBudgetID+"_"+date+"_"+time+formart;//保存时的名字
    string mapPath = Server.MapPath("../../");
    string path =mapPath + @"upfile\Budget\"+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString();
    if(!System.IO.Directory.Exists(path))
    {
    System.IO.Directory.CreateDirectory(path);
    }
    file.PostedFile.SaveAs(path + @"\" + newName); 
    }
    catch(Exception ex)
    {
    throw ex;}
      

  4.   

    TO:apcsherry(无敌神勇小超人) AND  sean168(凉风有兴,秋月无边)
    谢谢你们俩位,
    你说所说的都是用System.Web.UI.HtmlControls.HtmlInputFile控件的打开对话框来选中某个文件才可以上传,我所要的是不通过用户操作来用代码指定文件路径然后上传,
    例:C:\aa.txt
    怎么把他用代码附给HtmlInputFile控件呢?
    我试了好多方法都不行,
    请高手给个见意
      

  5.   

    昨天我刚刚做了一个跟这个有关的问题!
    我把方法告诉你,肯定没有问题的!
    前台:
    <INPUT class="TextBox" id="UP_FILE" style="VERTICAL-ALIGN: sub; WIDTH: 320px" type="file"
    accept="text/*" name="UP_FILE" RUNAT="server">
    在前台加一个这样的控建(在html控键项里面有)
    后台:
    HttpPostedFile  UpFile  =  UP_FILE.PostedFile;  //HttpPostedFile对象,用于文件属性  
    UpFile.SaveAs(Server.MapPath("/你要放的服务器文件夹/保存的文件名"));
      

  6.   

    楼上的说的很好,其实就是文件上传的问题.
    顺便提示.将Form的entType改为:enctype="multipart/form-data"
      

  7.   

    TO: ycrw(隐藏人物) 
    不行哦,
    HttpPostedFile  UpFile  =  UP_FILE.PostedFile;
    我想了想,换汤不换药~
    如果我要是现在有两个文件,例:
    C:\aa.txt
    C:\bb.txt我要是用for循环把这两个文件上传到服务器,怎么办?
      

  8.   

    如果那样的话,那我的页面上得放好多HttpPostedFile控件
    我的想法是一个HttpPostedFile控件,每次用户选择的路径存到一个字符串数组里
    然后用for循环把数组中的路径提取出来上传到服务器,其实问题就出在,应该如何为HttpPostedFile控件用代码赋FileName的值的问题!
      

  9.   

    <script language="JavaScript">
        function addFile()
        {
         var str = '<INPUT type="file" size="27" NAME="File">'
         document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
        }
     </script>
    动态加HttpPostedFile控件
    HttpPostedFile控件是不能赋值的
      

  10.   

    除了动态加HttpPostedFile控件,
    就没有别的办法了么!?