本文介绍了上传时无法在asp网络中找到文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用此代码上传ftp: protected void LinkBut​​ton1_Click( object sender,EventArgs e) { string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName); string ftpServerIP = *; string ftpUserName = *; string ftpPassword = *; FileInfo objFile = new FileInfo(filename); FtpWebRequest objFTPRequest; objFTPRequest =(FtpWebRequest)FtpWebRequest.Create( new Uri(ftpServerIP + / + objFile.Name)); objFTPRequest.Credentials = new NetworkCredential(ftpUserName,ftpPassword); objFTPRequest.KeepAlive = false ; objFTPRequest.UseBinary = true ; objFTPRequest.ContentLength = objFile.Length; objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile; int intBufferLength = 16 * 1024 ; byte [] objBuffer = new byte [intBufferLength]; FileStream objFileStream = objFile.OpenRead(); try { Stream objStream = objFTPRequest.GetRequestStream(); int len = 0 ; while ((len = objFileStream.Read(objBuffer, 0 ,intBufferLength))!= 0 ) { objStream.Write(objBuffer, 0 ,len); } objStream.Close(); objFileStream.Close(); Console.Write( 文件上传成功...); } catch (例外情况) { throw ex; } } 我的错误: System.IO.FileNotFoundException:找不到文件'... '。解决方案 替换以下内容 string filename = System.IO.Path.GetFileName(FileUpload1 .PostedFile.FileName); with string filename = FileUpload1.PostedFile.FileName.ToString( ); I use this code for upload with ftp:protected void LinkButton1_Click(object sender, EventArgs e) { string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName); string ftpServerIP = "*"; string ftpUserName = "*"; string ftpPassword = "*"; FileInfo objFile = new FileInfo(filename); FtpWebRequest objFTPRequest; objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + objFile.Name)); objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword); objFTPRequest.KeepAlive = false; objFTPRequest.UseBinary = true; objFTPRequest.ContentLength = objFile.Length; objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile; int intBufferLength = 16 * 1024; byte[] objBuffer = new byte[intBufferLength]; FileStream objFileStream = objFile.OpenRead(); try { Stream objStream = objFTPRequest.GetRequestStream(); int len = 0; while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0) { objStream.Write(objBuffer, 0, len); } objStream.Close(); objFileStream.Close(); Console.Write("File upload success..."); } catch (Exception ex) { throw ex; } }my error :System.IO.FileNotFoundException: Could not find file '...'. 解决方案 Replace the following string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);with string filename = FileUpload1.PostedFile.FileName.ToString(); 这篇关于上传时无法在asp网络中找到文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 22:47