要求的技术是:先在网页保存一个文件(文件内容是页面上的动态数据)到客户端,怎样再将这个客户端的文件上传到web服务器上?
以下是我的测试代码片段:
js:
document.getElementById("oframe").Save("c:/temp/myfile.doc");document.getElementById("oframe").HttpInit();
document.getElementById("oframe").HttpAddPostCurrFile("FileData", "myfile.doc");
document.getElementById("oframe").HttpPost("http://mytest/upload.aspx");c#后台:for (int i = 0; i < Request.Files.Count; i++)
                        {
                            if ((Request.Files[i].FileName == "" && Request.Files[i].FileName != null))
                                continue;
                            if (Request.Files[i].ContentLength > 0)
                            {
                                string filename = System.IO.Path.GetFileName(Request.Files[i].FileName);
                               
                                HttpPostedFile file = Request.Files[i];
                                byte[] fileContents = new byte[file.ContentLength];
                                file.InputStream.Read(fileContents, 0, file.ContentLength);                                SPFile spFile = folder.Files.Add(filename, fileContents, true);                                spFile.Item.SystemUpdate();                                file.InputStream.Close();
                                file.InputStream.Flush();
                            }
                        }但是IE会出错:
请问高手们,有没好的思路或代码片段参考一下?
谢谢。

解决方案 »

  1.   

    虽然IE报错,但是文件已成功上传到 Web 服务器上,真是快要疯了.....
      

  2.   

    由于是 连贯动作 (本地和服务器都要保存一份文件),FileUpload控件又不能动态赋值,请问还有没更好的方案?
      

  3.   

    你可以动态创建<input type=file啊。
    即使你动态创建的,也必须通过用户自己点击浏览才能上传的
      

  4.   

    先在网页保存一个文件(文件内容是页面上的动态数据)到客户端,怎样再将这个客户端的文件上传到web服务器上?你直接保存到服务器上一份不就得了吗???然后再发送给客户端
      

  5.   

    问题自己解决了,还是用 HttpPost 到新页面上传,将c#代码优化了一下,排除了IE错误。
    现在开始散分,接分的进来...........