xml文件未保存在vb.net的app_data中 [英] xml file not saving in app_data in vb.net

查看:121
本文介绍了xml文件未保存在vb.net的app_data中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我已经在appdata里面创建了xml文件vs 2010年



它运行正常,但它没有保存它显示访问被拒绝它是由另一个人使用



我的代码是

hi friends i have already created xml file in appdata inside vs 2010

it working fine but it is not saving it showing access denied it is using by another person

my code is

If (IO.File.Exists(Server.MapPath("~/App_Data/XMLFile1.xml"))) Then

            Dim document As XmlReader = New XmlTextReader(Server.MapPath("~/App_Data/XMLFile1.xml"))

            While (document.Read())

                Dim type = document.NodeType


                If (type = XmlNodeType.Element) Then

                    If document.Name <> dpFiles.SelectedItem.Text Then

                        Dim innertext As String
                        innertext = document.ReadInnerXml.ToString()

                        Dim filename As String = Server.MapPath("~/App_Data/XMLFile1.xml")

                        'create new instance of XmlDocument
                        Dim doc As New XmlDocument()

                        'load from file
                        doc.Load(filename)
                        Try

                            Dim node As XmlNode = doc.CreateNode(XmlNodeType.Element, "" & dpFiles.SelectedItem.Text & "", Nothing)
                            'node.InnerText = "this is new node";

                            'create title node
                            Dim nodeTitle As XmlNode = doc.CreateElement("" & dpFiles.SelectedItem.Text & "")
                            'add value for it
                            nodeTitle.InnerText = lblRandomNumber.Text

                            'create FileName
                            Dim nodeFileName As XmlNode = doc.CreateElement("FileName")
                            nodeFileName.InnerText = txtFileName.Text

                            'create FilePath
                            Dim nodeFilePath As XmlNode = doc.CreateElement("FilePath")
                            nodeFilePath.InnerText = txtFolderPath.Text

                            'create FileDesc
                            Dim nodeFileDesc As XmlNode = doc.CreateElement("Description")
                            nodeFileDesc.InnerText = txtDesc.Text

                            'add to parent node
                            node.AppendChild(nodeTitle)
                            node.AppendChild(nodeFileName)
                            node.AppendChild(nodeFilePath)
                            node.AppendChild(nodeFileDesc)

                            'add to elements collection
                            doc.DocumentElement.AppendChild(node)

                            'save back
                            doc.Save(filename)
                        Catch ex As Exception
                            MsgBox(ex.ToString())
                        End Try
                    End If
                End If
            End While

推荐答案

是的,访问该文件的其他进程也是你的过程。

你打开文件至少两次:

Yes, and the other process accessing the file is also your process.
You open the file at least twice:
Dim document As XmlReader = New XmlTextReader(Server.MapPath("~/App_Data/XMLFile1.xml"))



然后多次进入一个循环 - 好吧,可能只是因为失败:


and then several times in a loop - well, likely once only because of the failure:

Dim filename As String = Server.MapPath("~/App_Data/XMLFile1.xml")
Dim doc As New XmlDocument()
doc.Load(filename)



找出你的内容想做。然后相应地构造代码。我不敢相信你在阅读时想要将数据添加到该文件中 - 而是事后再这样做。


Find out what you want to do. And then structure the code accordingly. I cannot believe that you want to add data to that file while you are reading it - rather do that afterwards.


这篇关于xml文件未保存在vb.net的app_data中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆