Okay, so I’ve got this code (in VB, which I don’t really know) that gets files from a flash file reference list and uploads them:
<%@ Import Namespace=“System.IO” %>
<script language=“vbscript” runat=“server”>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim hfc As HttpFileCollection = Request.Files
For i As Integer = 0 To hfc.Count - 1
Dim hpf As HttpPostedFile = hfc(i)
If hpf.ContentLength > 0 Then
'Save the file to some mapped location i.e. “MyFiles”
hpf.SaveAs(Server.MapPath(“MyFiles”) & "" & Path.GetFileName(hpf.FileName))
End If
Next i
Catch ex As Exception
'some backend error handle
End Try
'Response.Write(“Hello”)
End Sub
This works perfectly… I don’t know how to use VB properly tho and there’s other features I wanna add, so I’m trying to convert this snippet to C#, where am I going wrong?:
protected void Page_Load(object sender, EventArgs e)
{
HttpFileCollection hfc = Request.Files;
int i;
for (i = 0; i<hfc.Count-1; i++) {
HttpPostedFile hpf = hfc*;
if (hpf.ContentLength > 0) {
hpf.SaveAs(Server.MapPath("MyFiles") + "\\" + Path.GetFileName(hpf.FileName));
}
}
}
I’ve added “using System.IO” at the top (I normally prefer to keep my code in a seperate to the aspx page)… But this doesn’t work… Why?