Scott Hanselman'ın blogunda bir MVC dosyası yüklemeye çalışırken example. Ben VB.NET onu dönüştürülürSystem.Web.HttpPostedFileBase'den System.Web.HttpPostedFile'a nasıl döküm uygularım?
foreach (string file in Request.Files)
{
HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
if (hpf.ContentLength == 0)
continue;
string savedFileName = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Path.GetFileName(hpf.FileName));
hpf.SaveAs(savedFileName);
}
:
For Each file As String In Request.Files
Dim hpf As HttpPostedFile = TryCast(Request.Files(file), HttpPostedFile)
If hpf.ContentLength = 0 Then
Continue For
End If
Dim savedFileName As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(hpf.FileName))
hpf.SaveAs(savedFileName)
Next
Ama derleyici geçersiz döküm özel durum alıyorum:
Value of type 'System.Web.HttpPostedFileBase' cannot be converted to 'System.Web.HttpPostedFile'.
Ben bu örnek kodu ile belaya girdi Hanselman, örneğini 2008-06-27'de yayınladı ve o zamanlar çalıştığını düşünüyorum. MSDN benzer örneklere sahip değil, bu yüzden ne veriyor?
Bu çalıştı, teşekkürler. –
EK BİLGİ: Beni seviyorsanız ve bu işlevi ayrı bir projede oluşturuyorsanız, HttpPostedFileBase öğesine başvuruda bulunmak için System.Web.Abstractions.dll dosyasını eklemeniz gerekir: http://efreedom.com/Question/1-1911151/CSharp-Reference-HttpPostedFileBase –
@tvanfosson bu bilgiyi arıyorum, neden HttpPostedFile yerine HttpPostedFileBase? Paylaşabileceğin bir bağlantın var mı? – codingbiz