Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [VB.NET] Effettuare download di file per data tramite http

    Salve a tutti,

    sono nuovo del forum, e volevo chiedere come poter effettuare il download di file da un sito avente data maggiore di...
    Ho provato ad utilizzare questo comando:
    codice:
    Dim dataaggsoft As Date = #1/10/2014#
    If System.IO.File.GetCreationTime("http://miosito/FILE.exe").Date >= dataaggsoft Then
     My.Computer.Network.DownloadFile ("http://miosito/FILE.exe", "C:\")
    End If
    Ma mi restituisce il seguente errore:

    Eccezione non gestita di tipo 'System.ArgumentException' in mscorlib.dll
    Ulteriori informazioni: I formati URI non sono supportati.


    C'è qualche altro tipo di comando da poter utilizzare?

    Grazie mille in anticipo
    Ultima modifica di MItaly; 16-02-2014 a 18:52 Motivo: Tag CODE, sezione errata

  2. #2

    Moderazione

    Benvenuto sul forum!
    • Le discussioni relative a VB.NET non sono trattate qui, ma nell'apposita sottosezione;
    • il codice va specificato tra tag [CODE] ... [/CODE], altrimenti perde l'indentazione.


    Correggo io e provvedo a spostare il thread; nel frattempo ti consiglio di dare un'occhiata al regolamento.
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Quanto al tuo problema, è normale, il metodo che stai cercando di usare serve solo per i file memorizzati su file system locale. Per verificare se una risorsa fornita via HTTP è stata modificata da una certa data, devi costruirti una richiesta HTTP con l'header If-Modified-Since, cosa che in .NET si può fare tramite la proprietà HttpWebrequest.IfModifiedSince (guarda l'esempio in fondo alla pagina).
    Amaro C++, il gusto pieno dell'undefined behavior.

  4. #4
    Salve MItaly, chiedo scusa ma ancora non so muovermi bene.
    Ho provato a seguire la guida compilando in questo modo ma non mi pensa proprio:

    '' Create a new 'Uri' object with the mentioned string.
    Dim aggexe As New Uri("http://mio_sito/FILE.exe")
    '' Create a new 'HttpWebRequest' object with the above 'Uri' object.
    Dim myHttpWebRequest As Net.HttpWebRequest = CType(Net.WebRequest.Create(aggexe), Net.HttpWebRequest)
    '' Create a new 'DateTime' object.
    'Dim targetDate As DateTime = DateTime.Now
    'targetDate.AddDays(-7.0)
    'myHttpWebRequest.IfModifiedSince = targetDate
    Dim dataaggsoft As DateTime = #1/10/2014#
    myHttpWebRequest.IfModifiedSince = dataaggsoft
    Try
    ' Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
    Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
    Console.WriteLine("Response headers for recently modified page" + ControlChars.Cr + "{0}" + ControlChars.Cr, myHttpWebResponse.Headers)
    Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
    Dim streamRead As New StreamReader(streamResponse)
    Dim readBuff(256) As [Char]
    Dim count As Integer = streamRead.Read(readBuff, 0, 256)
    Console.WriteLine(ControlChars.Cr + ControlChars.Cr)
    While count > 0
    Dim outputData As New [String](readBuff, 0, count)
    Console.Write(outputData)
    count = streamRead.Read(readBuff, 0, 256)
    End While
    ' Close the Stream object.
    streamResponse.Close()
    streamRead.Close()
    ' Release the HttpWebResponse Resource.
    myHttpWebResponse.Close()
    Console.WriteLine(ControlChars.Cr)
    Console.Read()
    Catch f As WebException
    If f.Response IsNot Nothing Then
    If CType(f.Response, HttpWebResponse).StatusCode = HttpStatusCode.NotModified Then
    Console.WriteLine((ControlChars.Cr + "File troppo vecchio" + dataaggsoft))
    Else
    Console.WriteLine(ControlChars.Cr + CType(f.Response, HttpWebResponse).StatusCode)
    End If
    Else
    Console.WriteLine(ControlChars.Cr + f.Message)
    End If
    End Try


    Molto probabilmente non riesco a compilarlo bene. chiedo scusa ancora ma è la prima volta che mi imbatto nelle proprietà HttpWebRequest.IfModifiedSince, ho sempre usato ftp (senza pensare alle date ovviamente).
    Se mi potete dare una mano???
    Grazie infinite

  5. #5
    Ah, chiedo scusa, non uso librerie ma solo Private Sub ai "Button"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.