日期:2014-05-18  浏览次数:20824 次

在网页保存一个文件到客户端,怎样再将该文件上传到web服务器上?
要求的技术是:先在网页保存一个文件(文件内容是页面上的动态数据)到客户端,怎样再将这个客户端的文件上传到web服务器上?
以下是我的测试代码片段:
js:
JScript code


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#后台:
C# code

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会出错:


请问高手们,有没好的思路或代码片段参考一下?
谢谢。

------解决方案--------------------
非常恐怖的搞法,如果IE安全允许,你不是可以把用户的任意文件收集到服务器上去了。
------解决方案--------------------
Fileupload控件上传上去
------解决方案--------------------
除非他主动选择上传,不然你怎么可能有权利访问到客户端的盘符呢?
那我是不是可以认为你可以提取任何客户端的文件呢?
------解决方案--------------------
你可以动态创建<input type=file啊。
即使你动态创建的,也必须通过用户自己点击浏览才能上传的


------解决方案--------------------
先在网页保存一个文件(文件内容是页面上的动态数据)到客户端,怎样再将这个客户端的文件上传到web服务器上?

你直接保存到服务器上一份不就得了吗???然后再发送给客户端