困扰好几天了,怎么都取不到值,查了很多资料,比如FORM标记中加enctype="multipart/form-data",然后也用了很多第三方上传控件,也都取不到值,非常着急!!!
难道会跟机器的什么权限有关?
非常着急!!!!!!!!!!能帮我解决了再加多少分都可以。客户等不及了

解决方案 »

  1.   

    为什么不用asp.net里的upload控件
      

  2.   

    兄弟们,我现在是非常着急
    我用的是HTMLINPUT控件,它的file1.PostedFile.FileName;老是说没实例化,我查了好几天了,网上一般说的解决方法我都试过了,还是照样出那个错……高手快来帮兄弟一把!!!
      

  3.   

    在FORM中如果有runat=server,就不用enctype="multipart/form-data
      

  4.   

    在工具箱html中添加File Field控件,然后单击右键作为服务器控件运行。
    在C:\Inetpub\wwwroot\upLoad(应用程序在iis中的目录)目录下创建一个upLoad的文件夹(名字可以变化)
    下面是具体的编程
    VB语法:
    Dim FullFileName As String = Me.UpLoadFile.PostedFile.FileName
    Dim FileName As String = Me.UpLoadFile.PostedFile.FileName.Substring(FullFileName.LastIndexOf("\") + 1)
            Dim FileType As String = Me.UpLoadFile.PostedFile.FileName.Substring(FullFileName.LastIndexOf(".") + 1)
            UpLoadFile.PostedFile.SaveAs(Server.MapPath("upLoad") & "\" & FileName)
            C#语法
            string fullfileName=this.file1.postedFile.fileNmae;
            string fileName=this.File1.PostedFile.FileName.Substring(fullFileName.LastIndexOf("\\")+1);
            string type= fullFillName.Substing(fullFileName.LastIndexOf(".");
            File1.PostedFile.SaveAs(server.MapPath("upLoad")+"\\"+fileName);如果有问题请与qq:407775797联系
      

  5.   

    是不是以前已经用过HTMLINPUT控件,被删除后后台定义的没删完.建议在老项目里面新建一页面测试.
      

  6.   

    给你个多文件上传的例子:
    <%@ Page language="c#" Codebehind="upload.aspx.cs" AutoEventWireup="false" Inherits="test.upload" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>upload</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <script language="javascript">
      function addFile()
      {
      var str = '<input type="file" size="50" name="File">'
      document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
      }
      
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server" enctype="multipart/form-data">
    <div align="center">
    <h3>多文件上传</h3>
    <p id="MyFile"><input type="file" size="50" name="file"></p>
    <p>
    <input type="button" value="增加(Add)" onclick="addFile()"> <input type="button" value="重置(ReSet)" onclick="this.form.reset()">
    <asp:Button Runat="server" Text="上传" ID="UploadButton"></asp:Button>
    </p>
    <p>
    <asp:Label ID="strStatus" Runat="server" Font-Name="宋体" Font-Bold="true" Font-Size="9pt" Width="500px"
    BorderStyle="None" BackColor="white"></asp:Label>
    </p>
    </div>
    </form>
    </body>
    </HTML>.cs:::
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace test
    {
    /// <summary>
    /// upload 的摘要说明。
    /// </summary>
    public class upload : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button UploadButton;
    protected System.Web.UI.WebControls.Label strStatus;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (this.IsPostBack) this.SaveImages(); 

    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    private Boolean SaveImages() 

    ///'遍历File表单元素 
    HttpFileCollection files = HttpContext.Current.Request.Files;  /// '状态信息 
    System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); 
    strMsg.Append("上传的文件分别是:<hr color=red>"); 
    try 

    for(int iFile = 0; iFile < files.Count; iFile++) 

    ///'检查文件扩展名字 
    HttpPostedFile postedFile = files[iFile]; 
    string fileName, fileExtension; 
    fileName = System.IO.Path.GetFileName(postedFile.FileName); 
    if (fileName != "") 

    fileExtension = System.IO.Path.GetExtension(fileName); 
    strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString()+ "<br>"); 
    strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>"); 
    strMsg.Append("上传文件的文件名:" + fileName + "<br>"); 
    strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>"); 
    ///可根据扩展名字的不同保存到不同的文件夹 
    ///注意:可能要修改你的文件夹的匿名写入权限。

    postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);



    // if (fileName != "") 
    // { 
    // fileExtension = System.IO.Path.GetExtension(fileName); 
    // strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString()+".rar" + "<br>"); 
    // strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>"); 
    // strMsg.Append("上传文件的文件名:" + fileName + "<br>"); 
    // strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>"); 
    // ///可根据扩展名字的不同保存到不同的文件夹 
    // ///注意:可能要修改你的文件夹的匿名写入权限。
    // postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/ss/") + fileName);
    //
    // } 
    //

    strStatus.Text = strMsg.ToString(); 
    return true; 

    catch(System.Exception Ex) 

    strStatus.Text = Ex.Message; 
    return false; 


    }
    }
      

  7.   

    private void cmd_Upload_Click(object sender, System.EventArgs e)
     {
       if(File_Files.PostedFile.FileName != "")
         {
            string strAttachName = File_Files.PostedFile.FileName.Substring (File_Piture.PostedFile.FileName.LastIndexOf("."));
    string Path = Server.MapPath("../Image/MenuItem/") + System.Guid.NewGuid()     + strAttachName;
    File_Files.PostedFile.SaveAs(Path);
    img_PackagePic.ImageUrl = Path.Replace(Server.MapPat(@"..\..\") , "http://" + Request.Url.Host + "/").Replace("\\" , "/");
    }
    }
    看看还行啊!