# From VB to C# file uploading code snippet, help me translate?

**URL:** <https://forum.kirupa.com/t/from-vb-to-c-file-uploading-code-snippet-help-me-translate/259814>\
**Category:** Uncategorized\
**Created:** [May 8, 2008, 10:27pm UTC](https://forum.kirupa.com/t/from-vb-to-c-file-uploading-code-snippet-help-me-translate/259814 "2008-05-08T22:27:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanaeda](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kanaeda](https://forum.kirupa.com/u/kanaeda)\
**Post date:** [May 8, 2008, 10:27pm UTC](https://forum.kirupa.com/t/from-vb-to-c-file-uploading-code-snippet-help-me-translate/259814/1 "2008-05-08T22:27:57Z")

</div>

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](http://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 &gt; 0) {

           hpf.SaveAs(Server.MapPath("MyFiles") + "\\" + Path.GetFileName(hpf.FileName));
        }
    }
}

```

I’ve added “using [System.IO](http://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?
