如何在计算机中保存XML文件?

时间:2023-01-14 10:27:40

In my project my app receives an XML from another program. I want to save this XML file in the folder in my PC. But if there is another XML file that will come, the XML will be added in the folder not overwrite the existing XML. How can I achieve it?

在我的项目中,我的应用程序从另一个程序接收XML。我想将此XML文件保存在PC中的文件夹中。但是如果有另一个XML文件,XML将被添加到文件夹中而不会覆盖现有的XML。我怎样才能实现它?

I am using this code right now but I don't know why I got an access denied error.

我现在正在使用此代码,但我不知道为什么我有一个访问被拒绝错误。

 System.IO.File.WriteAllText(@"C:\XML", abc);

1 个解决方案

#1


1  

First of all, the error that you receive is because of Windows UAC which denies users without Administrator privileges to write on the C:\ disk. Create a folder in which you have access, for example "c:\temp\" and write your files in there.

首先,您收到的错误是由于Windows UAC拒绝没有管理员权限的用户在C:\磁盘上写入。创建一个您有权访问的文件夹,例如“c:\ temp \”并在其中写入您的文件。

Also, you specify a file and not folder.

此外,您指定文件而不是文件夹。

And if you don't want to overwrite the file, just make sure to generate a unique filename (a guid perhaps).

如果您不想覆盖该文件,只需确保生成一个唯一的文件名(也许是一个guid)。

#1


1  

First of all, the error that you receive is because of Windows UAC which denies users without Administrator privileges to write on the C:\ disk. Create a folder in which you have access, for example "c:\temp\" and write your files in there.

首先,您收到的错误是由于Windows UAC拒绝没有管理员权限的用户在C:\磁盘上写入。创建一个您有权访问的文件夹,例如“c:\ temp \”并在其中写入您的文件。

Also, you specify a file and not folder.

此外,您指定文件而不是文件夹。

And if you don't want to overwrite the file, just make sure to generate a unique filename (a guid perhaps).

如果您不想覆盖该文件,只需确保生成一个唯一的文件名(也许是一个guid)。