0

我想根据选择的类型创建一个文件名设置的 xml 文件。

If type.Value = "H" Then
            fileName = "Hotels.xml"
        ElseIf type.Value = "F" Then
            fileName = "Flights.xml"
        ElseIf type.Value = "T" Then
            fileName = "Tours.xml"
        End If

xmlFile = Server.MapPath("") + "/files/" + fileName
DT.WriteXml(xmlFile, XmlWriteMode.DiffGram)

但是文件名遇到'变量文件名在被赋值之前被使用。我尝试将 xmlFile 部分更改为条件的顶部,但它仍然相同。

4

1 回答 1

0

也许您在 if 条件中使用它之前还没有初始化“fileName”字符串变量。当您第一次声明它时,将其初始化为 null,如下所示。代码在 C# 中,因为我在 VB.NET 中有点弱,但我想你明白我在这里的意思。

string fileName = null;

在 VB.NET 中应该是(我认为)

Dim fileName As String = Nothing

希望这有帮助。

问候,

萨马尔

于 2013-07-26T08:20:57.267 回答