Visual Studio Community 2015でテキストファイルをダウンロードできません。アプリケーション(1.0.0.0)のバージョン番号を含むOneDrive Publicフォルダのテキストファイルです。私が使用するダウンロードリンクは、手動で開くと完全に動作しますが、VBコードが実行されると、テキストファイルが正しくダウンロードされますが、ファイルを開くと空白になり、どこが間違っているのか分かりません。 Module1のでVB.NETでオンラインテキストファイルが空白になっているのはなぜですか?
、私はダウンロードして、その後、ファイルを読み込むためのサブのためのサブあります
Module Module1
' Public variables
Public tempPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Temp"
Sub DownloadToTemp(filePath As String)
' Download a text file, ready to read contents
If Not IO.Directory.Exists(tempPath & "\Temp") Then
IO.Directory.CreateDirectory(tempPath & "\Temp")
End If
Try
My.Computer.Network.DownloadFile _
(address:=filePath,
destinationFileName:=tempPath & "\TempText.txt",
userName:=String.Empty,
password:=String.Empty,
showUI:=False,
connectionTimeout:=10000,
overwrite:=True)
Catch ex As Exception
MsgBox("Can't read file" & vbCrLf & ex.Message)
End Try
End Sub
Sub ReadFile()
Dim fStream As New IO.FileStream(tempPath & "\TempText.txt", IO.FileMode.Open)
Dim sReader As New System.IO.StreamReader(fStream)
Dim sArray As String() = Nothing
Dim index As Integer = 0
Do While sReader.Peek >= 0
ReDim Preserve sArray(index)
sArray(index) = sReader.ReadLine
index += 1
Loop
fStream.Close()
sReader.Close()
' Test
Dim fileContents As String = Nothing
If sArray Is Nothing Then
MsgBox("No Data Found")
Exit Sub
End If
For index = 0 To UBound(sArray)
fileContents = fileContents & sArray(index) & vbCrLf
Next
MessageBox.Show(fileContents)
End Sub
End Module
を、それらがメインコードから呼び出されている:だから
Private Sub frmSplash_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblVersion.Text = "v" & Application.ProductVersion
' Check available version online
Call DownloadToTemp("https://onedrive.live.com/download?resid=DE2331D1649390C1!16974&authkey=!AH2cr1S1SHs9Epk&ithint=file%2ctxt")
Call ReadFile()
End Sub
、すべてがそうですエラーや例外は発生しませんが、VBコードがダウンロードするファイルは空白ですが、コードからダウンロードリンクを手動でクリックすると内容はそのままダウンロードされます。なぜこれが起こっているのか誰にも見えますか?
@VisualVincent印象。私は直接ダウンロードリンクを取得する方法を見つけるためにもう一度試しましたが、Microsoftが意図的に避けているようです。リダイレクトを許可する代わりに、私は間違いなくHttpWebRequestクラスコードを使用します。再度、感謝します! – JasonPy
うれしい私は助けることができました!私は私の答えのコメントを見たので、ダブルポストする必要はありません。 ;) –