Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 1.0/1.1
Zippare
mercoledì 05 dicembre 2007 - 15.52
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
crostino75
Profilo
| Newbie
11
messaggi | Data Invio:
mer 5 dic 2007 - 15:52
ciao a tutti.
vorrei scrivere una pagina web che consenta ad un utente di scegliere 1 o più file e di creare uno zip, il cui nome è associato ad una logica.
mi sono fatto convinto, forse sbaglio, che prima bisogna uppare sul server remoto di file scelti dall'utente e poi, successivamente, zipparli... il tutto, sempre, sul server remoto di (faccio il nome) ARUBA.
ho trovato un paio di script in rete che mi agevolano, usando la SharpZipLib...
... però siccome è la prima volta che mi cimento in tale situazione, trovo delle difficoltà.
Con questo codice carico, correttamente, sul server remoto il file scelto dall'utente e sino a qua non ho problemi:
If CType(e.Item.FindControl("f1"), HtmlInputFile).Value = "" Then
Me.Label1.Text = "Error: You must enter a file name."
Return
End If
If CType(e.Item.FindControl("f1"), HtmlInputFile).PostedFile.ContentLength > 0 Then
Try
CType(e.Item.FindControl("f1"), HtmlInputFile).PostedFile.SaveAs(("d:\inetpub\webs\bettinazzinet\public\temp\" & CType(e.Item.FindControl("f1"), HtmlInputFile).Value))
Me.Label1.Text = "File uploaded successfully to <b>c:\temp\" & _
CType(e.Item.FindControl("f1"), HtmlInputFile).Value & "</b> on the Web server."
Catch exc As Exception
Me.Label1.Text = "Error saving file <b>c:\temp\" & _
CType(e.Item.FindControl("f1"), HtmlInputFile).Value & "</b><br>" & exc.ToString() & "."
End Try
End If
è la fase di ZIP che mi sfugge:
Dim objCrc32 As New Crc32
Dim zos As ZipOutputStream
zos = New ZipOutputStream(File.Create("d:\inetpub\webs\bettinazzinet\public\" & e.Item.Cells(1).Text & "-" & e.Item.Cells(2).Text & ".zip"))
il file zip lo crea
' il faut mettre les noms relatifs pour que Windows puisse lire le fichier zip correctement (d'où la modif du currentdirectory)
Dim strFile(2) As String 'vous créez votre tableau comme vous voulez, c'est juste un tableau...
strFile(0) = "d:\inetpub\webs\bettinazzinet\public\temp\" & CType(e.Item.FindControl("f1"), HtmlInputFile).Value & ""
strFile(1) = "d:\inetpub\webs\bettinazzinet\public\temp\" & CType(e.Item.FindControl("f2"), HtmlInputFile).Value & ""
strFile(2) = "d:\inetpub\webs\bettinazzinet\public\temp\" & CType(e.Item.FindControl("f3"), HtmlInputFile).Value & ""
Me.Label2.Text = strFile(1)
i file sono sul server remoto
For i As Integer = 0 To strFile.Length - 1
Dim strmFile As FileStream = File.OpenRead(strFile(i))
Dim abyBuffer(CInt(strmFile.Length - 1)) As Byte
strmFile.Read(abyBuffer, 0, abyBuffer.Length)
Dim objZipEntry As ZipEntry = New ZipEntry(strFile(i))
objZipEntry.DateTime = DateTime.Now
objZipEntry.Size = strmFile.Length
strmFile.Close()
objCrc32.Reset()
objCrc32.Update(abyBuffer)
objZipEntry.Crc = objCrc32.Value
zos.PutNextEntry(objZipEntry)
zos.Write(abyBuffer, 0, abyBuffer.Length)
Next
zos.Finish()
zos.Close()
forse apro uno stream in remoto su se stesso???
Mi aiutate a capire, per favore?
Grazie
Emanuele
crostino75
Profilo
| Newbie
11
messaggi | Data Invio:
mer 5 dic 2007 - 15:56
ho dimenticato a scrivere che ottengo il seguente errore
come se mancasse qualcosa...
Could not find a part of the path 'd:\inetpub\webs\bettinazzinet\public\temp\'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'd:\inetpub\webs\bettinazzinet\public\temp\'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path 'd:\inetpub\webs\bettinazzinet\public\temp\'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +1971376
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +114
System.IO.File.OpenRead(String path) +30
WJV_Admin.zip.DataGrid1_UpdateCommand(Object source, DataGridCommandEventArgs e) +2858
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +105
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +471
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !