我现在在一个页面中上传多张图片,对应不同的类别(如:位置图,平面图,图片数量可以根据客户的需要添加的,<input type='file' />是用js生成的),在页面提交之前我在js中把每个类别的<input type='file' />的value赋值给一个隐藏控件以便在.cs中保存的时侯好区分,我在保存的时侯:
        string fileName = 。;
        string SoftDown = Request.Form["hidSoftDown"];
        HttpFileCollection files = Request.Files;
        for (int i = 0; i < files.Count; i++)
        {
            string oldFile = files[i].FileName.Trim();
            if (SoftDown.IndexOf(oldFile) >= 0)
            {
              SoftDown = SoftDown.Replace("<Path>" + oldFile + "</Path>", "<Path>" + fileName + "</Path>");
               。。
但是结果是:
files[i].FileName在IE中它获取的值是:C:\AA\A.TXT
在firefox中它获取的值是:A.TXT,造成上面SoftDown的值没有被修改
-----------------------------------
我该怎么办呢?或者对于我这种情况还有其他好的处理方式吗?

解决方案 »

  1.   

    判断是哪种游览器,
    if(window.ActiveXObject){
           //IE
        }else{
            //其他浏览器
        }
      

  2.   

    你的SoftDown 本来是什么值
      

  3.   

    我在客户端就是通过循环把下面的字符串str赋值给一个隐藏控件hidSoftDown的,所以SoftDown就是一个xml的字符串。
        var table = document.getElementById(Table);
        var str = "";
        for(var i = 1; i < table.rows.length; i ++)
        { 
            var row = table.rows[i];
            var order = Trim(row.cells[3].getElementsByTagName("input")[0].value);
            if(row.cells[1].getElementsByTagName("input")[0].value != "")
            {
               if(row.cells[1].getElementsByTagName("input")[0].type == "file")
               {
                    var file = Trim(row.cells[1].getElementsByTagName("input")[0].value);
                str += "<File><Path>" + file + "</Path><Desc>"
                    + Trim(row.cells[2].getElementsByTagName("input")[0].value) + "</Desc><Order>" 
                    + order + "</Order><Size>"
                    + file + "</Size></File>";
                 。
      

  4.   

    就统一支取文件名
    try:var file = Trow.cells[1].getElementsByTagName("input")[0].value;
    var index = file.lastIndexOf("\\");
    if(index > 0)
       file = file.substr(index+1);str += "<File><Path>" + file + "</Path><Desc>"
    + Trim(row.cells[2].getElementsByTagName("input")[0].value) + "</Desc><Order>"
    + order + "</Order><Size>"
    + file + "</Size></File>";
      

  5.   

    统一只取文件名也不怎么好,万一用户的不同目录下有相同名字的文件,那也是有问题的.
    现在我想知道有什么方法获取那些js生成的<input type='file' />控件的ID没?或者有什么比我这种方法更好的方法代替我的做法没?