我尝试从D:\ Data \复制文件到D:\ WPSystem \ APPS \ Install \我有错误访问被拒绝,谁可以帮助我和/或重建源?
袖珍文件管理器可以添加新文件,没有任何错误
有人提到过“但是要将文件复制到apps文件夹,请尝试使用StorageFolder和StorageFile类”
但我不知道如何应用它
资料来源:Click
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);
}
}
}
}
1 回答
如果你得到一个访问被拒绝的例外问题不在代码中 . 运行应用程序的用户无权运行此应用程序,或者文件/目标文件夹由于某种原因被锁定 .