Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert php to ASP.NET C# 1

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
Hello,

How could I convert this to asp.net c#?
Code:
<?php
     $pageID = $_GET['pageID'];

     // Execute Query
     $msSqlQry = mssql_query("SELECT * FROM myLinks WHERE txtPageID = '$pageID'")
          or die ("Unable to run query");
          
     // Iteration loop, for each row in rowset
     $lineNumber = 1;
    while ($row = mssql_fetch_assoc($msSqlQry))

    {
        // Assigning variables from cell values
        $txtFileID           = $row["txtFileID"];
        $txtPageID           = $row["txtPageID"];
        $expireTime      = $row["txtExpireTime"];
        $txtFileName      = $row["txtFileName"];
        $txtToName           = $row["txtToName"];
        $txtToEmail      = $row["txtToEmail"];
        $txtFromName     = $row["txtFromName"];
        $txtFromEmail      = $row["txtFromEmail"];
        $numDownloads      = $row["numDownloads"];
          //get current time
          $currentTime      = date("YmdHis");
          
          //get basename
          $txtBasename = basename($txtFileName);
          
          //make sure link has not expired
          if ($currentTime > $expireTime)
          {
               echo "<tr><td align=\"left\">";
               echo $lineNumber . ") <font color=\"#FF0000\">Link Expired - </font>" . $txtBasename;
               echo "</td></tr>";
          }
          else
          {
             // Outputting data to browser
               echo "<tr><td align=\"left\">";
               echo($lineNumber . ') <A HREF=downloadAction.php?fileID=' . $txtFileID . '>');
                  echo('Click to download:  ' . $txtBasename .'</A>');
               echo "</td></tr>";
          }//end if
          $lineNumber++;
          $pageExists = 1;
    }//end while
     
?>
</table>

It's only easy when you know how.
 
No. 2 pencil with sharpener. Just kidding; Kurt, the code's logic seems straightforward, i.e., what it is accomplishing. Couldn't you right away just start writing this in C#?

If you don't know C# I would pass this on to a programmer -- there is no place that I know of where you can dump this code in a textbox, click a button, and get C# out. Now there is a place on the web where you can do this between VB and C#, but none that I know of that'll accomplish it with php and C#.

I would first translate the logic into english, and then re-translate it into C# (I program in VB so can't help on that note). If I were facing this problem I would go to a php forum, etc, find out what the business logic is, and then re-write it in C#.
 
Hello,

I was going to try the migration assistant but I dont' have Visual Studio .NET. I'm using Visual Web Developer Express.

I'm trying to learn C# but its proving to be difficult.



It's only easy when you know how.
 
So far I have this. It displays the info in a datagrid but this doesn't allow me to compare the date of each record returned and then display expired or a link.


Code:
    string pageID;
    pageID = Request.QueryString["pageID"];
    //Response.Write(pageID);

    //query database   
    objCmd = new SqlCommand("SELECT txtPageID, txtFileID, txtExpireTime, txtFileName FROM myLinks WHERE txtPageID=@pageID ORDER BY txtFileName", objConn);
    objCmd.Parameters.Add("@pageID", pageID);

    objConn.Open();
    objRdr = objCmd.ExecuteReader();

    myDataGrid.DataSource = objRdr;
    myDataGrid.DataBind();

    objRdr.Close();
    objConn.Close();

It's only easy when you know how.
 
Isadore - Thanks :)

Kurt, the examples show them using VS, I don't see anything that says you can't use it with the express version. It's worth a shot to see if it will work with express.

Jim
 
Under console they talk about using PHPConvert.exe command-line tool. I searched my hard drive after installing the program and it doesn't exist. I'm not sure where to get it.

It's only easy when you know how.
 
For the example you've given, I really think it's more work trying to convert it from PHP to C# with a tool. Simply rewrite the code and use a DataGrid to display the data. Bind the DataGrid to the Reader like you have done, and use the ItemDataBound event to set the conditional formatting.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top