C# .NET - PHP to C# Convert - Asked By Jem Savery on 02-Nov-11 06:45 AM

Hi Friends,

Does anybody know how to convert PHP code to C#.net code? Is there any converter available?

I need following PHP code to be converted to C#

$uploaddir = './uploads/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "http://iphone.zcentric.com/uploads/{$file}";

Please help me.

Thanks in advance,
dipa ahuja replied to Jem Savery on 02-Nov-11 06:47 AM
There is no convert. You can use ASP.NET and re-implement your site from scratch. You can always implement some pages in PHP, others in Python/WSGI, Java, and so on…
One great opportunity to re-use you PHP code is using Phalanger, see
This is PHP for .NET. You can use it to develop regular PHP code or include in ASP.NET solution. Visual Studio integration is also available. You can use stepwise debugging of you PHP code through Visual Studio debugger!
Jitendra Faye replied to Jem Savery on 02-Nov-11 06:48 AM

Try this code-



void UploadButton_Click(object sender, EventArgs e)


if (FileUploadControl.HasFile)





string filename = Path.GetFileName(FileUploadControl.FileName);


"~/Image/") + filename);

StatusLabel.Text =

"Upload status: File uploaded!";


catch (Exception ex)


StatusLabel.Text =

"Upload status: The file could not be uploaded. The following error occured: " + ex.Message;




Hope this will help you,.

Suchit shah replied to Jem Savery on 02-Nov-11 07:29 AM


  • Download Web Matrix. Web Matrix is a free tool for developing ASP.NET Applications. It comes with a walkthrough tutorial and pre-built templates that show you how to accomplish common tasks like connecting to a database and returning the results as a table. You can download Web Matrix from http://www.asp.net/webmatrix.
  • Visit the http://www.asp.net/Forums/ShowForum.aspx?tabindex=1&ForumID=44. Get your questions answered by members of the ASP.NET team at Microsoft and the ASP.NET community.
  • Check out the http://www.asp.net/starterkits. The ASP.NET Starter Kits are a set of pre-built sample applications including e-commerce sites, portals and more—available complete with source code for you to use.
  • Use the PHP to ASP.NET 1.x Migration Assistant to migrate PHP applications to ASP.NET 1.x.


    Certain links are broken in this page, you might want to read the following guide about this tool to help you.


    Before doing it also have a look at
    Migrating from PHP to ASP.NET (http://msdn.microsoft.com/en-us/library/aa479002.aspx)

    Kirtan Patel replied to Jem Savery on 02-Nov-11 08:00 AM
    Untitled document
    protected void Button1_Click(object sender, EventArgs e)
      if (FileUpload1.HasFile)
        string Filename = FileUpload1.FileName;
        FileUpload1.SaveAs(Server.MapPath("/uploads") + "/" + Filename);
        Page.RegisterClientScriptBlock("", "<script>alert('File Uploaded');</script>");
    Jem Savery replied to Kirtan Patel on 02-Nov-11 08:18 AM
    Hi Friends,

    I am thankful to you but I do not use Fileupload control for this as the image will be coming from iPhone application like this:

    NSString *urlString = @"http://yourserver.com/upload.php";
    NSString *filename = @"filename";
    = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    NSString *boundary = @"---------------------------14737809831466499882746641449";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    NSMutableData *postbody = [NSMutableData data];
    [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
    [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postbody appendData:[NSData dataWithData:YOUR_NSDATA_HERE]];
    [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:postbody];

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

    And the URL I need to provide is a .aspx page which will store the image in database in binary format.
    The datatype for that field is "image".