xmlファイルを作成するための簡単なC#コードを作成しました。現在は自分の現在のプロジェクトが存在するPCの場所に保存しますcode.But問題は、コードの最後の行で例外が生成され、System.Xml.dllで 'System.UnauthorizedAccessException'が発生したことを示しています。追加情報: 'C:\ Users'パスへのアクセスVisual Studioの2013 \ \管理\ドキュメントプロジェクト\ ClassLibrary1の\ ClassLibrary1' の\ denied.Belowは、生成したXMLファイルを保存するために私のコードです:XMLファイルをlinqを使ってC言語で保存する必要があります
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ClassLibrary1
{
class Class14
{
public static void Main()
{
XDocument xml = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("Students",
new XElement("Student", new XAttribute("ID", 101),
new XElement("Name", "kamal"),
new XElement("Gender", "Male"),
new XElement("Marks", "800")),
new XElement("Student", new XAttribute("ID", 102),
new XElement("Name", "Sapna"),
new XElement("Gender", "Female"),
new XElement("Marks", "900")),
new XElement("Student", new XAttribute("ID", 103),
new XElement("Name", "Raju"),
new XElement("Gender", "Male"),
new XElement("Marks", "870"),
new XElement("Student", new XAttribute("ID", 104),
new XElement("Name", "Sushant"),
new XElement("Gender", "Male"),
new XElement("Marks", "700"))
)));
xml.Save(@"C:\Users\admin\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1");
}
}
}
のようなセキュリティ権限で遊ぶことができます。エラーはかなり明確です。アプリを実行しているユーザーには、必要な場所へのアクセス権がありません。したがって、別の場所を選択してください。 –