DevTrain Startseite Visual Studio 1 Magazin  
  
  
SUCHEN:  
ARTIKEL ONLINE: 525   

Kategorien
.NET
Datenbanken
Web
XML

Allgemein
Camp
Foren
Events
Persönliche Einstellungen
Registrieren
Prämien Shop
Kontakt
Impressum
Über DevTrain

Autoren



 

Forum: ASP.NET | Thema: Upload File - Delete File | Von: G. Guest ( 10.03.2005 13:53)

Guten Tag,
Ich habe ein Code gebastellt, dass ich eine Datei mit asp.net hochladen kann,
Wie kann ich die Datei, die ich hochgeladen habe mit ein Mausklick löschen: (file.delete)
den Code siehst wie folgendes so aus!

<%@ Import Namespace="System.IO"%>
<html>
<head>
<title>File Management</title>
<script language="VB" runat="server">

Dim currentDir As String
Dim directorySeparatorChar As Char = Path.DirectorySeparatorChar


Sub Page_Load(sender As Object, e As EventArgs)

Dim root As String = "C:\temp"
Dim thisPage As String = Request.Path

currentDir = Request.Params("dir")
If currentDir Is Nothing Then
currentDir = root
End If
If Not currentDir.StartsWith(root) Then
currentDir = root
End If

Dim sb As New StringBuilder(4096)

If Not currentDir.Equals(Root) Then
' not at the root
Dim currentDirParent As String
Dim lastIndex As Integer = _
currentDir.LastIndexOf(directorySeparatorChar)
If lastIndex <> -1 Then
currentDirParent = currentDir.Substring(0, lastIndex)
Else
currentDirParent = currentDir
End If
sb.Append("<a href=").Append(thisPage)
sb.Append("?dir=").Append(Server.UrlEncode(currentDirParent))
sb.Append("><img width=30 border=0 src=images/Up.gif></a><br>")
End If

DoUpload()

sb.Append("<br><img border=0 src=images/OpenFolder.gif> ")
sb.Append("<font face=verdana>")
sb.Append(currentDir)
sb.Append("</font>")
sb.Append("<br>")

sb.Append("<table>")
sb.Append("<tr bgcolor=#D8D8D8>")
sb.Append("<td width=200><font face=verdana size=3>Name</font></td>")
sb.Append("<td><font face=verdana size=3>Type</font></td>")
sb.Append("<td><font face=verdana size=3>Size</font></td>")
sb.Append("<td><font face=verdana size=3>Modified</font></td>")
sb.Append("</tr>")


Dim dirs() As String
Try
dirs = Directory.GetDirectories(currentDir)

Dim d As String
For Each d In dirs
Dim dirName As String = Path.GetFileName(d)
sb.Append("<tr>")
sb.Append("<td><img src=images/Folder.gif> ")
sb.Append("<a href=").Append(thisPage)
sb.Append("?dir=").Append(Server.UrlEncode(currentDir))
sb.Append(directorySeparatorChar)
sb.Append(Server.UrlEncode(dirName))
sb.Append(">").Append(dirName).Append("</a>")
sb.Append("</td>")
sb.Append("<td><font face=verdana size=2>folder</font></td>")
sb.Append("<td> </td>")
sb.Append("<td><font face=verdana size=2>")
sb.Append(Directory.GetLastWriteTime(currentDir & _
directorySeparatorChar.ToString() & dirName).ToString())
sb.Append("</font></td>")
sb.Append("</tr>")


Next

Catch ex As Exception
End Try


Try
Dim dirInfo As New DirectoryInfo(currentDir)
Dim files() As FileInfo
files = dirInfo.GetFiles()

Dim f As FileInfo
For Each f In files
Dim filename As String = f.Name
sb.Append("<tr>")
sb.Append("<td><img src=images/File.gif> ")
sb.Append("<a href=FileDownload.aspx?file=")
sb.Append(Server.UrlEncode(currentDir))
sb.Append(directorySeparatorChar)
sb.Append(Server.UrlEncode(filename))
sb.Append(">").Append(filename).Append("</a>")
sb.Append("</td>")
sb.Append("<td><font face=verdana size=2>file</font></td>")
sb.Append("<td><font face=verdana size=2>")
sb.Append(f.Length.ToString())
sb.Append("</font></td>")
sb.Append("<td><font face=verdana size=2>")
sb.Append(File.GetLastWriteTime(currentDir & _
directorySeparatorChar.ToString() & f.Name).ToString())
sb.Append("</font></td>")
sb.Append("</tr>")
Next
Catch ex As Exception
End Try

sb.Append("</table>")
dirContent.Text = sb.ToString()
End Sub


Sub DoUpload()

If Not (uploadedFile.PostedFile Is Nothing) Then
Try
Dim postedFile = uploadedFile.PostedFile
Dim filename As String = Path.GetFileName(postedFile.FileName)
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength
postedFile.SaveAs(currentDir & _
directorySeparatorChar.ToString() & filename)
Catch ex As Exception
message.Text = "Failed uploading file"
End Try
End If
End Sub


</script>
</head>
<body>
<form runat="server" enctype="multipart/form-data" >
<asp:Label id="dirContent" runat="server"/>
<asp:Label id="message" runat="server"/>
<p>
<hr>

<%-- File Upload --%>
<font face=verdana>Select File to Upload:</font>
<input id="uploadedFile" type="file" runat="server">
<input type=button id="upload"
value="Upload"
OnServerClick="Page_Load"
runat="server">
<p>

</form>
</body>
</html>




Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!

 Betreff:
 Nachricht: Den Beitrag finden Sie nun unter: http://beta.devtrain.de/foren Die Benutzerdaten und Foreninhalte von beta.devtrain.de und www.devtrain.de sind die selben.
Sie können sich dort sogar per RSS über neue Inhalte informieren lassen.
Bei Problemen bitte direkt Mail an asp [AT] ppedv.de.

 Signatur:

  



Login
Username:


Passwort:






Passwort vergessen?

Advanced Developers Conference vom 14.-15. Februar 2011

© Copyright 2003 ppedv AG