如何在ASP.NET中删除目录?

时间:2015-04-20 10:41:04

标签: asp.net

我检查目录是否存在以及删除后。 我会删除目录和里面的每个图像。 有时会出现错误,就像另一个进程获取此文件一样。 如何删除目录?

<%@ Page Language="VB" Trace="false" Debug="true" aspcompat=true%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<script runat="server">
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim IdLocale = Request.form("IdLocale")
Command = New SqlCommand("DELETE FROM LOCALI WHERE ID='"+IdLocale+"'",Connection)
Command.ExecuteNonQuery()  
' Creo una variabile con il path della nuova cartella da crearea 
Dim Folder As String = Server.MapPath("images/foto/locali/"+IdLocale)
' Verifico che la cartella esisti...
if Directory.Exists(Folder) = True Then 
' ...Elimino la cartella
Directory.Delete(Folder, True)
End If
end sub
</script>

保存

Dim fileName As String 

If Request("name") IsNot Nothing then
fileName = Request("name")
else
fileName = String.Empty
end if

' Creo una variabile con il path della nuova cartella da crearea 
Dim Folder As String =     Server.MapPath("images/foto/locandine/"+Session("IdGuid"))
' Verifico che la cartella non esista già...
If Directory.Exists(Folder) = False Then 
' ...Creo la cartella al percorso specificato
Directory.CreateDirectory(Folder)
End If

Dim fileUpload As HttpPostedFile = Request.Files(0)

Dim fs = New FileStream(Path.Combine(Folder, fileName),FileMode.Create)

Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
fileUpload.InputStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, buffer.Length)

阅读

来自页面aspx ..和对象轮播..

0 个答案:

没有答案