小小问题:下边的代码我真的不知道如何转换!请各位帮帮忙...(在线等待,及时结帖)
VB中的代码(没有CODEBEHIND)如下:
Sub Page_Load()
'create physical path for the new file (in same folder as ASPX page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "newbooklist.xml"
'declare a variable to hold an XmlTextWriter object
Dim objXMLWriter As XmlTextWriter
Try
'create a new objXMLWriter object for the XML file
objXMLWriter = New XmlTextWriter(strXMLPath, Nothing)
outDocURL.innerHTML = "Writing to file: <b>" & strXMLPath & "</b>"
Catch objError As Exception
'display error details
outError.innerHTML = "<b>* Error while accessing document</b>.<br />" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution
End Try
'now ready to write (or "push") the nodes for the new XML document
'turn on indented formatting and set indent to 3 chararcters
objXMLWriter.Formatting = Formatting.Indented
objXMLWriter.Indentation = 3
'start the document with the XML declaration tag
objXMLWriter.WriteStartDocument()
'write a comment element including the current date/time
objXMLWriter.WriteComment("Created using an XMLTextWriter - " & Now())
'write the opening tag for the <BookList> root element
objXMLWriter.WriteStartElement("BookList")
'write the opening tag for a <Book> element
objXMLWriter.WriteStartElement("Book")
'add two attributes to this element's opening tag
objXMLWriter.WriteAttributeString("Category", "Technology")
Dim intPageCount As Integer = 1248 'numeric value to convert
objXMLWriter.WriteAttributeString("Pagecount", intPageCount.ToString("G"))
'write four elements, using different source data types
objXMLWriter.WriteElementString("Title", "Professional Video Recorder Programming")
Dim datReleaseDate As DateTime = #03/03/2000#
objXMLWriter.WriteElementString("ReleaseDate", datReleaseDate.ToString("yyyy-MM-dd"))
Dim intSales As Integer = 17492
objXMLWriter.WriteElementString("Sales", intSales.ToString("G"))
Dim blnHardback As Boolean = True
objXMLWriter.WriteElementString("Hardback", blnHardback.ToString())
'write the opening tag for the <AuthorList> child element
objXMLWriter.WriteStartElement("AuthorList")
'add two <Author> elements
objXMLWriter.WriteElementString("Author", "Francesca Unix")
objXMLWriter.WriteElementString("Author", "William Soft")
'close the <AuthorList> element
objXMLWriter.WriteEndElement()
'close the <Book> element
objXMLWriter.WriteEndElement()
'close the root <BookList> element
objXMLWriter.WriteEndElement()
'flush the current content to the file and close it
objXMLWriter.Flush()
objXMLWriter.Close()
'now open the new XML file and read it into a string
Dim strXMLResult As String
Dim objSR As StreamReader = File.OpenText(strXMLPath)
strXMLResult = objSR.ReadToEnd()
objSR.Close
objSR = Nothing
'and display the results in the page
outResults.innerHTML = "<pre>" & Server.HtmlEncode(strXMLResult) & "<pre>"
End Sub
我想把它转换成C#的代码,使用CODEBEHIND技术,当我只是进行简单的转换的时候,我发现在C#中好象不存在下边的方法:string strXMLPath=Left(strCurrentPath,InStrRev(strCurrentPath,"\"))+"newbooklist.xml";
....................也许是我C#功底太差的缘故吧,我在MSDN中去搜索InStrRev找到的却是VB中的一段代码.......请各位帮忙翻译一下吧!
我现在特别纳闷的地方是:如果我不知道在C#中的哪个方法,但是我又想在MSDN中去找,我应该怎么做,难道用汉字去搜索吗???好象此种方法常常得不到我想要得结果来着,还请各位给小弟我提点建议(我知道MSDN中有很多好东东,但是我不知道该如何使用来着,哎,晕!)...........先在此多谢各位了!!!!!!!