我试图在我的程序中打开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
为我锁定文件的方法。我该怎么办?