Click here to Skip to main content
12,690,140 members (31,163 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
please give me the below sample code is in php convert it into c# code.
code starts here:

$ratio2)    {
        else    {
          // we create a new image with the new dimmensions
        // resize the big image to the new created one
        // output the created image to the file. Now we will have the thumbnail into the file named by $filename

          //destroys source and destination images.
       function getExtension($str) {
               $i = strrpos($str,".");
               if (!$i) { return ""; }
               $l = strlen($str) - $i;
               $ext = substr($str,$i+1,$l);
               return $ext;

        //reads the name of the file the user submitted for uploading

    // if it is not empty
    if ($image)
        // get the original name of the file from the clients machine
        $filename = stripslashes($_FILES[$fileElementName]['name']);

        // get the extension of the file in a lower case format
        $extension = getExtension($filename);
        $extension = strtolower($extension);
        // if it is not a known extension, we will suppose it is an error, print an error message
        //and will not upload the file, otherwise we continue
        if (($extension != "jpg")  && ($extension != "jpeg") && ($extension != "png"))
            $error .= 'Unknown extension!';

            //compare the size with the maxim size we defined and print error if bigger
            if ($sizekb > MAX_SIZE*1024)
                $error .= 'You have exceeded the size limit!';
            else {

              //we will give an unique name, for example the time in unix time format
            //the new name will be containing the full path where will be stored (images folder)
            $copied = copy($_FILES[$fileElementName]['tmp_name'], $newname);
            //we verify if the image has been uploaded, and print error instead
            if (!$copied)
              $error .= 'Copy unsuccessfull!';
              // the new thumbnail image will be placed in images/thumbs/ folder
              // call the function that will create the thumbnail. The function will get as parameters
              //the image name, the thumbnail name and the width and height desired for the thumbnail

              //also add the users pic


      //--------- END SECOND SCRIPT --------------------------------------------------------------------

      //return variables to javascript
            $filename = $_FILES[$fileElementName]['name'];
            $filesize = round(($sizekb/1000), 0);
            $fileloc = $thumb_name;
            //for security reason, we force to remove all uploaded file
    $return_JSON = "";
    $return_JSON .= "{";
    $return_JSON .=             "error: '" . $error . "',\n";
    $return_JSON .=             "name: '" . $filename . "',\n";
    $return_JSON .=             "size: '" . $filesize . "',\n";
    $return_JSON .=             "loc: '" . $fileloc . "'\n";
    $return_JSON .= "}";
    echo $return_JSON;
Posted 2-Sep-13 23:33pm
Updated 3-Sep-13 11:38am
Madhugundi 3-Sep-13 4:35am
please refer the below link
jkirkerx 3-Sep-13 17:16pm
I wouldn't convert it, just write a new one in c#
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is not how CP usually works. Most important goal here is to learn and help learning.
You are supposed to try it on your own, and come here when you got stuck with something, with a concrete question about your code, design, etc.
Please have a look to What have you tried?[^] to see a good explanation about what I mean.
Don't forget people here don't get payed. And besides, if we give you a ready-to-go solution, it is not going to help you because you are not going to learn anything from it.

P.S. Written as solution to avoid this "question" to be in the unanswered list
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This is the quick answer forum and you will not find anyone to do all of your work for you. I recommend you get started on converting it and if you get stuck on a specific line then please ask.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 3 Sep 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100