プロジェクトフォルダーの一部にpngファイルをコピーしようとしていますが、試してみるとこのエラーが発生します。
別のプロセスで使用されているため、プロセスはファイル '....../Image.png' にアクセスできません。
他のプログラムがファイルにアクセスしていないことを保証できます。すべての winform デザイナー ウィンドウと、他のアプリケーションまたはウィンドウを閉じています。
これは私が使用しているコードです。このサイトで他のすべての回答を試しましたが、何も機能しません。これに関するヘルプがあれば大歓迎です!
region アセットのインポート関数
private void button_ImportAsset_Click(object sender, EventArgs e)
{
// Default to the directory which contains our content files.
string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
string relativePath = Path.Combine(assemblyLocation, "../../../../Content");
string contentPath = Path.GetFullPath(relativePath);
openFileDialog1.InitialDirectory = contentPath;
openFileDialog1.Title = "Load Asset";
openFileDialog1.Filter = "PNG Files (*.png)|*.png|" +
"DDS Files (*.dds)|*.dds|" +
"BMP Files (*.bmp)|*.bmp|" +
"All Files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// Creates new png version.
string newFileName = ((openFileDialog1.FileName));
string filename = openFileDialog1.FileName;
File.Copy(filename, newFileName, true);
// Creates new xnb version.
string outFileName =
STATIC_CONTBUILDER.BuildXNBFromFile((openFileDialog1.FileName));
// Copies the asset from the temporary build directory to the assets directory.
File.Copy(
Path.Combine(STATIC_CONTBUILDER.contentBuilder.OutputDirectory, outFileName),
Path.Combine(STATIC_CONTBUILDER.pathToContent, outFileName),
true);
}
Do_Refresh_XNB_Asset_List();
}
private void Do_Refresh_XNB_Asset_List()
{
listBox_Assets.Items.Clear();
string[] lst_Files =
Directory.GetFiles(STATIC_CONTBUILDER.pathToContent, "*.xnb", SearchOption.TopDirectoryOnly);
for (int i = 0; i < lst_Files.Length; i++)
{
listBox_Assets.Items.Add(
Path.GetFileNameWithoutExtension(
lst_Files[i]));
}
}
#endregion