开发者

some php to ASP.NET

开发者 https://www.devze.com 2023-01-09 05:47 出处:网络
anyone kind enough to transcr开发者_JS百科ibe this php to ASP.NET ?? thank you kindly in advance.

anyone kind enough to transcr开发者_JS百科ibe this php to ASP.NET ??

thank you kindly in advance.

jJ

<?php
if(isset($_POST['data']) && $_POST['data'] != '') {
 $output = $_POST['data']; 
 $newfile = time() . ".xml"; 
 $file = fopen ($newfile, "w"); 
 fwrite($file, $output); 
 fclose ($file);  
 echo 'file created: ' . $newfile;
} else {
 echo "not saved";
}
?>


Untested code but enough to get you started

if(!string.IsNullOrEmpty(Response.Form["data"]))
{
    string output = Response.Form["data"];
    string newfile = DateTime.Now.ToString("hhMMss")+".xml";
    File.WriteAllText(newfile, output);
    Response.Write("file created: " + newfile);
}
else
{
    Response.Write("not saved");
}

This was how I learned PHP so I felt obligated to pay back :)

Edit: As everyone else has said, you should of course don't use this as-is but instead use it for learning.


As far as I can see, this is not directly translateable to one chunk of ASP.NET-code as you'd probably want.

You need an .aspx-file, and you need the code behind (.aspx.cs-file) to do it in the most basic way. Opening, writing and closing a text file could be done like this. The rest relies on specific ASP.NET-techniques like using a <asp:whatever id="data"> element and then retrieving this code behind.

You're asking for a fairly simple task, and you would probably be better off if you took some time to look at ASP.NET yourself.

Edit: @Jesper Palm did more or less what I said was not possible in my first line. Weird use of the ASP.NET framework anyways, in my opinion. :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消