本文介绍了在asp.net中使用jquery使用webservice上传文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试使用webservice上传doc和pdf文件。 我有这样的错误I am trying to upload doc and pdf files using webservice.I have an error like thisSystem.ArgumentOutOfRangeException was unhandled by user code HResult=-2146233086 Message=Index was out of range. Must be non-negative and less than the size of the collection. 我的代码是my code is[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string uploadfile(string res) { HttpContext postedContext = HttpContext.Current; HttpPostedFile file = postedContext.Request.Files[0]; //HttpPostedFile file = HttpContext.Current.Request.Files[formData]; //HttpPostedFile hFile = postedContext.Request.Files[1]; string name = file.FileName; string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.FileName); string fileExtension = Path.GetExtension(file.FileName); //file.PostedFile.SaveAs("d:\\Resumes\\" + ISO_Date() + "_" + fileNameWithoutExtension + fileExtension); //File.Copy("d:\\Resumes\\" + ISO_Date() + "_" + fileNameWithoutExtension + fileExtension); file.SaveAs("d:\\Resumes\\" + ISO_Date() + "_" + fileNameWithoutExtension + fileExtension); return res; } static String ISO_Date() { return DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); } jquery函数jquery function<script type="text/javascript"> function finalupload() { var res = document.getElementById('txtSocialPassword').value; var newfile = document.getElementById("<%=file.ClientID%>").files[0]; alert(formData); //alert(res); $.ajax({ type: "POST", contentType: "application/json", url: "HuntableWebService.asmx/uploadfile", data: "{'res':'" + res + "'}", dataType: "JSON", async: true, success: function (response) { //var res = response.d; alert(response.d); } }); return false; }</script> 我正在尝试将简历保存到硬盘文件夹中。 please帮助我。 谢谢....I am trying to save resume in to harddisk folder.please help me.Thank you....推荐答案 我正在尝试将简历保存到硬盘文件夹中。 please帮助我。 谢谢....I am trying to save resume in to harddisk folder.please help me.Thank you....var res放在 inSys.Serialization.JavaScriptSerializer.serialize(); 之后尝试你的代码...after that try your code... 这篇关于在asp.net中使用jquery使用webservice上传文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 22:58