问题描述
請問有前輩用.net2.0vb下完成上傳嗎?我似乎在回傳json值得部分一直發生上傳接口錯誤..但我已經檢查過路徑應該都沒有錯我看範例給的upload中有以下stringjsonString(stringstr){str=str.Replace("\","\\");str=str.Replace("/","\/");str=str.Replace("'","\'");returnstr;}
做字串轉換請問這是必要的嗎?因為看demo文件只提到2,返回结构必需为json,并且结构如下:{"err":"","msg":"200906030521128703.gif"}弄了兩天實在不知道錯在哪...檔案也確實都有傳進網站資料夾中..附上小弟改寫的upload..請前輩們指點一下..(當中不少註解因為在做各種嘗試..)ImportsSystem.IOImportsSystem.SecurityImportsSystem.Web.UI.WebControlsPartialClassadmin_ws_uploadInheritsSystem.Web.UI.PageProtectedSubPage_Load(senderAsObject,eAsSystem.EventArgs)HandlesMe.LoadDiminputnameAsString="filedata"'表单文件域nameDimuploadedFilesAsHttpFileCollection=Request.FilesDimSavetoPosAsString=Server.MapPath("../WebFiles")DimiAsInteger=0DimNewNameAsStringDimmsgAsString="''"DimerAsString=""DimuploaddirAsString="../WebFiles"DimtargetAsStringDimlocalnameAsString'DoUntili=uploadedFiles.CountTryDimuserPostedFileAsHttpPostedFile=uploadedFiles(inputname)If(userPostedFile.ContentLength>0)ThenDimoFileNameAsString=System.IO.Path.GetFileName(userPostedFile.FileName)localname=userPostedFile.FileNameDimExtensionNameAsString=Path.GetExtension(userPostedFile.FileName).ToLower'取得副檔名NewName=Guid.NewGuid.ToString&ExtensionName'DimPicHeightAsDouble=0'DimPicWidthAsDouble=0'DimjAsInteger=0'DimbmpAsNewDrawing.Bitmap(userPostedFile.InputStream)'PicHeight=(bmp.Height)'PicWidth=(bmp.Width)'ResizeImage(bmp,NewName,SavetoPos,1000,50000)userPostedFile.SaveAs(SavetoPos&"/"&NewName)target=uploaddir&"/"&NewName'msg="'"&jsonString(target)&"'"'Response.write(jsonString(target))'Response.endmsg="{'url':'"&jsonString(target)&"','localname':'"&jsonString(localname)&"','id':'1'}"'Response.Write(msg)'Response.end()'IfNotResizeImage(bmp,NewName,SavetoPos,800,600)Then'userPostedFile.SaveAs(SavetoPos&NewName)'EndIf'Response.Write("{msg:'"&NewName&"'}")'Response.Redirect("InsertImageTable_Dialog.aspx?NewName="&NewName,True)elseer="您沒有選擇檔案!"EndIfi+=1'LoopCatchexAsExceptioner=ex.ToStringResponse.Write("{'err':'"&jsonString(er)+"','msg':"&msg&"}")Response.end()EndTryEndSubPublicFunctionjsonString(ByValstrAsString)AsString'str=str.Replace("\","\\")'str=str.Replace("/","\/")'str=str.Replace("'","\'")ReturnstrEndFunctionEndClass
先謝過至少有看完這文的前輩了!
解决方案
解决方案二:
VB.NET的啊,之前利用xheditor做过上传,不过是asp.net的
解决方案三:
引用1楼taomanman的回复:
VB.NET的啊,之前利用xheditor做过上传,不过是asp.net的
這篇我有翻到!不過C#我實在不熟..我自己改的這個就是從C#的範例參考出來的..但還是一直錯..orz還是感謝版主的回應!