我尝试将文件从 D:\Data\ 复制到 D:\WPSystem\APPS{GUID}\Install\ 并且出现错误访问被拒绝,谁能帮助我和/或重建源代码?
袖珍文件管理器可以添加新文件而不会出现任何错误
任何人都提到过“但是将文件复制到应用程序文件夹尝试使用 StorageFolder 和 StorageFile 类”
但我不知道如何应用它
来源:点击
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp1.Resources;
using System.IO;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
var directory = new DirectoryInfo("D:\\WPSystem\\") { Attributes = System.IO.FileAttributes.Normal };
directory.Attributes = System.IO.FileAttributes.Normal;
foreach (var info in directory.GetFileSystemInfos("*"))
{
info.Attributes = System.IO.FileAttributes.Archive;
}
var dir = directory.GetDirectories("apps").FirstOrDefault();
if (dir != null)
{
dir.MoveTo("D:\\WPSystem\\appsx");
var dir2 = new DirectoryInfo(@"D:\WPSystem\appsx\{GUID}\Install\");
var file = dir2.GetFiles("AppManifest.xaml").FirstOrDefault();
if (file != null)
{
file.Delete();
}
Directory.Move("D:\\WPSystem\\appsx", "D:\\WPSystem\\apps");
var data = new DirectoryInfo("D:\\Data\\");
var appmanifest = data.GetFiles("AppManifest.xaml").FirstOrDefault();
if (appmanifest != null)
{
appmanifest.CopyTo(
"D:\\WPSystem\\apps\\{GUID}\\Install\\File.bin");
}
}
MessageBox.Show("Success !");
//Application.Current.Terminate();
}
catch(Exception ex)
{
MessageBox.Show("Error"+ Environment.NewLine + ex.Message);
}
}
}
}