在运行时使用代码创建服务器后,如何刷新服务器上的文件夹

问题描述:

我在运行时创建了一个文件夹
我想在上面上传一些图片
我收到了此错误消息
(找不到路径的一部分)
刷新父文件夹时效果很好
现在我要做的就是在运行时使用代码刷新父文件夹
thnx为您提供帮助

I''ve created a folder on runtime
and i want to upload some pices on it
put I''ve got this error message
(Could not find a part of the path )
when I refresh the parent folder It works well
now all what i want is to refresh the parent folder on runtime with code
thnx for your help

您只需确保使用Server.MapPath来获取对创建的文件夹的限定"引用.您不必刷新".在Windows资源管理器中,您通常会刷新以查看是否从另一个资源管理器窗口创建了文件夹.这不适用于Web应用程序.如果您创建了它,那么它已经存在!并且,发布一些代码,这可能有助于我们其中一个发现问题.

看看这些链接-

http://msdn.microsoft.com/en-us/library/system. web.httpserverutility.mappath.aspx [ ^ ]

http://www.4guysfromrolla.com/webtech/121799-1.shtml [ ^ ]
You just have to make sure that you use Server.MapPath to get a "qualified" reference to the folder you created. You don''t have to "refresh". In windows explorer you normally refresh to see if you created the folder from another explorer window. This does not apply to a web application. If you created, it''s there already! And, post some code, it may help one of us find the issue.

Have a look at these links -

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^]

http://www.4guysfromrolla.com/webtech/121799-1.shtml[^]


谢谢非常感谢您的快速响应

这是我用于创建文件夹的代码
thank you very much for your Quick response

this is the code I use for create folders
Protected Sub Button10_Click(sender As Object, e As System.EventArgs) Handles Button10.Click
       If TextBox3.Text = Nothing Or TextBox4.Text = Nothing Then
           Exit Sub
       End If
       Dim Fname As String
       Dim path As String
       path = Request.PhysicalApplicationPath
       If FileUpload1.HasFile Then
           Fname = FileUpload1.FileName
           path += "\images\characters\"
           path += Fname

           FileUpload1.SaveAs(path)
       End If

       Dim linkpath As String = "abo-rashed.aspx?caracter=" + TextBox3.Text + "&txt=" + TextBox4.Text
       Session("caracter-name") = TextBox3.Text

       Dim doc As XDocument = XDocument.Load(CType(Session.Item("file"), String))
       ''Dim ele As XElement = New XElement("comment", TextBox3.Text)
       Dim ele As XElement = New XElement("cd", "")
       doc.Root.AddFirst(ele)

       Dim ele2 As XElement = New XElement("title", "images\characters\" + Fname)
       Dim ele1 As XElement = New XElement("link", linkpath)
       Dim ele3 As XElement = New XElement("txt", linkpath)



       doc.Root.Element("cd").Add(ele1, ele2, ele3)



       doc.Save(CType(Session.Item("file"), String))
       mysource()
       ''--------------------------------------------add folders---------------------------------
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text)
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text + "\bg")
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text + "\bg-real")
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text + "\card")
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text + "\card-real")
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text + "\logo")
       Directory.CreateDirectory(Request.PhysicalApplicationPath & "images\caracter-main\" + TextBox3.Text + "\trach")



       Server.Transfer("AdminCaracters.aspx")
   End Sub



这是我用来将图片上传到其中一个文件夹的代码



and this is the code I use for upload pices to one of this folders

Dim Fname1 As String
       Dim Fname2 As String
       Dim Fname3 As String
       Dim Fname4 As String
       Dim path1 As String
       Dim path2 As String
       Dim path3 As String
       Dim path4 As String
       Dim CNAME As String
       Dim pathlink As String
       If Not Session.Item("caracter-name") Is Nothing Then
           CNAME = Session.Item("caracter-name").ToString
       Else
           If Not TextBox3.Text = Nothing Then
               CNAME = TextBox3.Text
           End If
       End If
       If CNAME = Nothing Then
           Exit Sub
       End If
       pathlink = Request.PhysicalApplicationPath + "\images\caracter-main\" + CNAME + "\bg\"


       Fname1 = FileUpload2.FileName
       Fname2 = FileUpload3.FileName
       Fname3 = FileUpload4.FileName
       Fname4 = FileUpload5.FileName


       path1 = pathlink + Fname1
       path2 = pathlink + Fname2
       path3 = pathlink + Fname3
       path4 = pathlink + Fname4

       FileUpload2.SaveAs(path1)
       FileUpload3.SaveAs(path2)
       FileUpload4.SaveAs(path3)
       FileUpload5.SaveAs(path4)





   End Sub



再次感谢您



and thank you again


关于Server.MapPath没用
但是非常感谢
about Server.MapPath it didn`t work
but thnx so much