文件上传问题

ragweed_wg 2003-09-29 04:27:05
如下源码:
输入的路径为本地路径测试成功,但是如何将文件直接上传到其他主机的共享路径下呢?尝试过直接将可写的共享路径映射成本地的网络驱动器,文件上传失败“DirectoryNotFoundException: Could not find a part of the path "f:\"(其中F:为映射成的网络驱动器)”,请教如何实现向其他主机(无IIS)共享路径下上传。



<%@Import Namespace=" System.IO "%>
<html>
<BODY>
<SCRIPT LANGUAGE = "VB" RUNAT = "SERVER">
 Sub UploadFile_Clicked ( Sender as Object, e as EventArgs )
  Dim lstrFileName as string
  Dim lstrFileNamePath as string
  Dim lstrFileFolder as string
  ' 如果上传目录为空,就使用" c:\ "作为缺省上传目录
  ' 获得上传到服务器的目录名称
  if dir.value <> "" then
   lstrFileFolder = dir.value
  else
   lstrFileFolder = "f:\"
  end if

  ' 获得文件名称
  lstrFileName = loFile.PostedFile.FileName
   ' 注: loFile.PostedFile.FileName 返回的是   通过文件对话框选择的文件名,这之中包含了文件的目录信息
  lstrFileName = Path.GetFileName ( lstrFileName )
   ' 去掉目录信息,返回文件名称

  ' 判断上传目录是否存在,不存在就建立
  If ( not Directory.Exists ( lstrFileFolder ) ) Then
   Directory.CreateDirectory ( lstrFileFolder )
  End If

   '上传文件到服务器
  lstrFileNamePath = lstrFileFolder & lstrFileName
   ' 得到上传目录及文件名称
  loFile.PostedFile.SaveAs ( lstrFileNamePath )

   ' 获得并显示上传文件的属性
  FileName.Text = lstrFileName
   ' 获得文件名称
  FileType.Text = loFile.PostedFile.ContentType
   ' 获得文件类型
  FileLength.Text = cStr ( loFile.PostedFile.ContentLength )
   ' 获得文件长度
  FileUploadForm.visible = false
  AnswerMsg.visible = true
   ' 显示上传文件属性
  End sub
</SCRIPT >
<ASP:panel id = "FileUploadForm" visible = " true " runat = "server" >
<form method = "post" enctype = "multipart/form-data" runat = "server" >
 <h1 > 欢迎使用ASP.NET页面实现文件上传 </h1 >
  请选择上传到服务器的文件名称:
 <input id = "loFile" type = "file" runat = "server" > <br>
  请输入上传到服务器的目录名称:
 <input id = "dir" type = "text" runat = "server" > <br>
 <input type = "submit" value = "开始上传" OnServerClick = "UploadFile_Clicked" runat = "server" >
 <br>
</form >
</ASP:panel >

<ASP:panel id = "AnswerMsg" visible = " false " runat = "server" >
 谢谢使用ASP.NET页面实现文件上传 <br>
 成功上传
<ASP:label id = "FileName" runat = "server" /> <br>
 文件大小
<ASP:label id = "FileLength" runat = "server" />
字节<br>
文件类型
<ASP:label id = "FileType" runat = "server" /> <br>
</ASP:panel >
</BODY>
</HTML>
...全文
73 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ragweed_wg 2003-09-30
  • 打赏
  • 举报
回复
呵呵……对不起,设置确实是G:\qsxx.txt,刚才手工改了一下(因为前面我一直说F盘是网络驱动器)。
G盘也是网络驱动器,可写。
2002pine 2003-09-30
  • 打赏
  • 举报
回复
F:\qsxx.txt

?为什么会出现"G:\qsxx.txt".
[DirectoryNotFoundException: Could not find a part of the path "G:\qsxx.txt".]

你跟踪一下,
ragweed_wg 2003-09-30
  • 打赏
  • 举报
回复
F:\qsxx.txt (其中F为网络驱动器,可写)
Stack Trace:


[DirectoryNotFoundException: Could not find a part of the path "G:\qsxx.txt".]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
System.IO.FileStream..ctor(String path, FileMode mode) +52
System.Web.HttpPostedFile.SaveAs(String filename) +48
ASP.qsxx_aspx.UploadFile_Clicked(Object Sender, EventArgs e) +128
System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108
System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277


2002pine 2003-09-30
  • 打赏
  • 举报
回复
你看一下,lstrFileNamePath的值是什么?
ragweed_wg 2003-09-30
  • 打赏
  • 举报
回复
本地共享路径的网络驱动器可以,其他计算机的不通,可能需要设置权限……哪位大虾知道如何设置?
ragweed_wg 2003-09-30
  • 打赏
  • 举报
回复
Up
ragweed_wg 2003-09-30
  • 打赏
  • 举报
回复
你输入的上传到服务器的目录名称是什么呢?
lucidaxy 2003-09-30
  • 打赏
  • 举报
回复
是不是把盘符和卷标搞混了
ragweed_wg 2003-09-30
  • 打赏
  • 举报
回复
??????????
ragweed_wg 2003-09-29
  • 打赏
  • 举报
回复
再顶………………
ragweed_wg 2003-09-29
  • 打赏
  • 举报
回复
嗯???不会吧……
f:盘为我的网络驱动器,运行提示:
Could not find a part of the path "F:\".]
lucidaxy 2003-09-29
  • 打赏
  • 举报
回复
我检查过了,网络驱动器没有问题可以上传的,看看是不是半角全角的问题
ragweed_wg 2003-09-29
  • 打赏
  • 举报
回复
????

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧