一些 php 到 ASP.NET

发布于 2024-09-12 05:19:15 字数 363 浏览 3 评论 0原文

有好心人可以将此 php 转录为 ASP.NET 吗?

预先感谢您。

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";
}
?>

anyone kind enough to transcribe 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";
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘年祭陌 2024-09-19 05:19:15

未经测试的代码,但足以让你开始

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");
}

这就是我学习 PHP 的方式,所以我觉得有义务回报:)

编辑:正如其他人所说,你当然不应该按原样使用它,而是用它来学习。

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.

jJeQQOZ5 2024-09-19 05:19:15

据我所知,这并不能像您可能想要的那样直接转换为一大块 ASP.NET 代码。

您需要一个 .aspx 文件,并且需要背后的代码(.aspx.cs 文件)以最基本的方式执行此操作。打开、写入和关闭文本文件可以像这样完成。其余部分依赖于特定的 ASP.NET 技术,例如使用 元素,然后检索后面的代码。

您要求执行一项相当简单的任务,如果您花一些时间亲自了解 ASP.NET,您的情况可能会更好。

编辑:
@Jesper Palm 或多或少做了我所说的在我的第一行中不可能实现的事情。在我看来,ASP.NET 框架的使用无论如何都是奇怪的。 :-)

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. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文