并不是说我对您的操作方式有任何问题,但这可能会少一些代码:
'fn: virtually unique file name based on date and time
Dim fn As String = "QR_" & String.Format("{0:MMddyyhhmmss}", DateTime.Now()) & ".png"
Dim txt As String = "Hello World"
Try
Dim client As New System.Net.WebClient
client.DownloadFile("http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=" & txt, Server.MapPath("~/TempFiles/" & fn))
client = Nothing
Catch
End Try
'I have an <asp:label> on my form so I can quickly test if the file downloaded.
lblTest.Text = "<a href='~/TempFiles/" & fn & "' target='_blank'>Success?</a>"
好吧,我用 VB 为 ASP.NET 编写了这个。如果有人试图在网站上执行此操作,这会有所帮助。