如何把代码中的VB语言转换为C#(2)
<%@ImportNamespace="System.Xml"%><%@ImportNamespace="System.IO"%><%@ImportNamespace="...
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System"%>
<script language="VB" runat="server">
Sub button1_Click(Sender As object,e as eventargs)
'判断文件是否存在
If (File.Exists(Server.MapPath(TextBox1.Text +".xml")))
Response.Write("文件名已经存在,请重新选文件名!")
Else
'首先将数据插入新闻列表中
Dim CurrNode As XMLNode
Dim xmldoc As New xmldocument()
'加载索引文件
xmldoc.load(Server.MapPath("contents.xml"))
dim insstr as string
'生成新闻索引
insstr="<topic><title>" & TextBox2.Text & "</title><href>main.aspx?name=" & TextBox1.Text & "</href></topic>"
Dim docFrag As XmlDocumentFragment=xmldoc.CreateDocumentFragment()
docFrag.InnerXml = InsStr
CurrNode=xmldoc.DocumentElement
'插入新闻索引队列中
currNode.InsertAfter(docFrag, currNode.LastChild)
'保存索引文件
xmldoc.Save (Server.MapPath("contents.xml"))
'把TextBox5中的文件换成符合xml格式的内容
Dim xmlfile As String
xmlfile=TextBox5.text
xmlfile=xmlfile.Replace("<","< ")
xmlfile=xmlfile.Replace(">","> ")
xmlfile=xmlfile.Replace("'","'")
xmlfile=xmlfile.Replace (chr(13)+chr(10),"</paragraph><paragraph>")
'把数据写入新建的xml文件中去
Dim doc as xmldocument
doc=new XmlDocument()
insstr="<?xml version='1.0' encoding='GB2312'?><document><title>"
insstr &=TextBox2.Text &"</title><abstract>" & TextBox4.Text
insstr &="</abstract><author>" &TextBox3.Text &"</author><content><paragraph>"
insstr &=xmlfile &"</paragraph></content></document>"
doc.LoadXml(insstr)
doc.Save (Server.MapPath(TextBox1.Text +".xml"))
Response.Write("You hava input the article!")
TextBox1.Text=""
TextBox2.Text=""
TextBox3.Text=""
TextBox4.Text=""
TextBox5.Text=""
End If
End Sub
</script>
<HTML>
<HEAD>
</HEAD>
<Body bgcolor="lightgrey">
<Form runat="server">
<p>梦幻驿站新闻发布系统 </P>
文件名:
<asp:textbox id=TextBox1 runat="Server"/>
<Asp:RequiredFieldValidator id="valid1"
ControlToValidate="Textbox1" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
文章名称:
<asp:textbox id=TextBox2 runat="server"/>
<Asp:RequiredFieldValidator id="valid2"
ControlToValidate="Textbox2" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
作者:
<asp:textbox id=TextBox3 runat="server"/>
<Asp:RequiredFieldValidator id="valid3"
ControlToValidate="Textbox3" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
摘要:<p>
<asp:textbox id=TextBox4 textmode="MultiLine" width="70%" runat="server"/>
<p>
内容:<p>
<asp:textbox id=TextBox5 textmode="MultiLine" rows=6 width="70%" runat="server"/>
<p>
<asp:Button id="submit" text="提交" OnClick="Button1_Click" runat="server"/>
</Form>
</Body>
</HTML>
如何把代码中的VB语言转换为C#? 展开
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System"%>
<script language="VB" runat="server">
Sub button1_Click(Sender As object,e as eventargs)
'判断文件是否存在
If (File.Exists(Server.MapPath(TextBox1.Text +".xml")))
Response.Write("文件名已经存在,请重新选文件名!")
Else
'首先将数据插入新闻列表中
Dim CurrNode As XMLNode
Dim xmldoc As New xmldocument()
'加载索引文件
xmldoc.load(Server.MapPath("contents.xml"))
dim insstr as string
'生成新闻索引
insstr="<topic><title>" & TextBox2.Text & "</title><href>main.aspx?name=" & TextBox1.Text & "</href></topic>"
Dim docFrag As XmlDocumentFragment=xmldoc.CreateDocumentFragment()
docFrag.InnerXml = InsStr
CurrNode=xmldoc.DocumentElement
'插入新闻索引队列中
currNode.InsertAfter(docFrag, currNode.LastChild)
'保存索引文件
xmldoc.Save (Server.MapPath("contents.xml"))
'把TextBox5中的文件换成符合xml格式的内容
Dim xmlfile As String
xmlfile=TextBox5.text
xmlfile=xmlfile.Replace("<","< ")
xmlfile=xmlfile.Replace(">","> ")
xmlfile=xmlfile.Replace("'","'")
xmlfile=xmlfile.Replace (chr(13)+chr(10),"</paragraph><paragraph>")
'把数据写入新建的xml文件中去
Dim doc as xmldocument
doc=new XmlDocument()
insstr="<?xml version='1.0' encoding='GB2312'?><document><title>"
insstr &=TextBox2.Text &"</title><abstract>" & TextBox4.Text
insstr &="</abstract><author>" &TextBox3.Text &"</author><content><paragraph>"
insstr &=xmlfile &"</paragraph></content></document>"
doc.LoadXml(insstr)
doc.Save (Server.MapPath(TextBox1.Text +".xml"))
Response.Write("You hava input the article!")
TextBox1.Text=""
TextBox2.Text=""
TextBox3.Text=""
TextBox4.Text=""
TextBox5.Text=""
End If
End Sub
</script>
<HTML>
<HEAD>
</HEAD>
<Body bgcolor="lightgrey">
<Form runat="server">
<p>梦幻驿站新闻发布系统 </P>
文件名:
<asp:textbox id=TextBox1 runat="Server"/>
<Asp:RequiredFieldValidator id="valid1"
ControlToValidate="Textbox1" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
文章名称:
<asp:textbox id=TextBox2 runat="server"/>
<Asp:RequiredFieldValidator id="valid2"
ControlToValidate="Textbox2" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
作者:
<asp:textbox id=TextBox3 runat="server"/>
<Asp:RequiredFieldValidator id="valid3"
ControlToValidate="Textbox3" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
摘要:<p>
<asp:textbox id=TextBox4 textmode="MultiLine" width="70%" runat="server"/>
<p>
内容:<p>
<asp:textbox id=TextBox5 textmode="MultiLine" rows=6 width="70%" runat="server"/>
<p>
<asp:Button id="submit" text="提交" OnClick="Button1_Click" runat="server"/>
</Form>
</Body>
</HTML>
如何把代码中的VB语言转换为C#? 展开
3个回答
展开全部
<script language="C#" runat="server">
public void button1_Click(object Sender, EventArgs e)
{
//判断文件是否存在
if ((File.Exists(Server.MapPath(TextBox1.Text + ".xml")))) {
Response.Write("文件名已经存在,请重新选文件名!");
} else {
//首先将数据插入新闻列表中
XMLNode CurrNode = default(XMLNode);
xmldocument xmldoc = new xmldocument();
//加载索引文件
xmldoc.load(Server.MapPath("contents.xml"));
string insstr = null;
//生成新闻索引
insstr = "<topic><title>" + TextBox2.Text + "</title><href>main.aspx?name=" + TextBox1.Text + "</href></topic>";
XmlDocumentFragment docFrag = xmldoc.CreateDocumentFragment();
docFrag.InnerXml = insstr;
CurrNode = xmldoc.DocumentElement;
//插入新闻索引队列中
CurrNode.InsertAfter(docFrag, CurrNode.LastChild);
//保存索引文件
xmldoc.Save(Server.MapPath("contents.xml"));
//把TextBox5中的文件换成符合xml格式的内容
string xmlfile = null;
xmlfile = TextBox5.text;
xmlfile = xmlfile.Replace("<", "< ");
xmlfile = xmlfile.Replace(">", "> ");
xmlfile = xmlfile.Replace("'", "'");
xmlfile = xmlfile.Replace(Strings.Chr(13) + Strings.Chr(10), "</paragraph><paragraph>");
//把数据写入新建的xml文件中去
xmldocument doc = default(xmldocument);
doc = new XmlDocument();
insstr = "<?xml version='1.0' encoding='GB2312'?><document><title>";
insstr += TextBox2.Text + "</title><abstract>" + TextBox4.Text;
insstr += "</abstract><author>" + TextBox3.Text + "</author><content><paragraph>";
insstr += xmlfile + "</paragraph></content></document>";
doc.LoadXml(insstr);
doc.Save(Server.MapPath(TextBox1.Text + ".xml"));
Response.Write("You hava input the article!");
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
}
}
</script>
展开全部
学习C# 然后看明白这段代码是干什么的,然后用C#重写!
追问
具体怎么改,我学的是C/C++,C#和VB根本没接触过,希望可以得到您的帮助。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下载sharpdevelop 里面有一个转换工具
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |