0

我试图在我的程序中打开一个 XML 文件以进行写访问。我的程序使用XmlDataProvider. 我找不到一种方法来完成这两者:

Partial Class MainWindow

  'XmlData As XmlDataProvider - Declared in MainWindow.xaml
  Private m_FileName As String = Nothing
  Private m_FileNumber As Integer


  Public Sub OpenFile(fileName As String)
    If m_FileName IsNot Nothing Then CloseFile()

    m_FileName = fileName
    m_FileNumber = FreeFile
    FileOpen(m_FileNumber, m_FileName, OpenMode.Binary, OpenAccess.Default, OpenShare.LockWrite)
    XmlData.Source = New Uri(m_FileName)
    ' IOException: The process cannot access the file "C:\path\filename.xml" because it is already in use by a different process.
    ' I translated the error message, I hope you know which one I mean.
  End Sub

  Public Sub CloseFile()
    If m_FileName Is Nothing Then Exit Sub

    XmlData.Source = Nothing
    FileClose(m_FileNumber)
    m_FileName = Nothing
  End Sub
End Class

我也找不到告诉XmlDataProvider我为我锁定文件的方法。我能做些什么?

4

0 回答 0