在网页保存一个文件到客户端,怎样再将该文件上传到web服务器上?
要求的技术是:先在网页保存一个文件(文件内容是页面上的动态数据)到客户端,怎样再将这个客户端的文件上传到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");
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(); } }