异常详细信息: System.UnauthorizedAccessException: 对路径“C:\Users\lenovo\Documents\Visual Studio 2015\WebSites\TaskManageSystem\src\FileBuffer”的访问被拒绝。
ASP.NET 无权访问所请求的资源。请考虑对 ASP.NET 请求标识授予访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}\ASPNET,在 IIS 6 和 IIS 7 上为网络服务,在 IIS 7.5 上为配置的应用程序池标识)。如果应用程序正在通过 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。
要将 ASP.NET 访问权限授予某个文件,请在文件资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。
要打开文件的时候就出错了
以下是我的压缩文件代码
public string SourceFolderPath = "C:\Users\lenovo\Documents\Visual Studio 2015\WebSites\TaskManageSystem\src\FileBuffer";
public void ZipFolder(string zipFilePath) {
using (Package package = Package.Open(zipFilePath, System.IO.FileMode.Create)) {
DirectoryInfo di = new DirectoryInfo(SourceFolderPath);
ZipDirectory(di, package);
}
}
//遍历资源文件函数
private void ZipDirectory(DirectoryInfo di, Package package) {
foreach (FileInfo fi in di.GetFiles()) {
string relativePath = fi.FullName.Replace(SourceFolderPath, string.Empty);
relativePath = relativePath.Replace("\","/");
PackagePart part = package.CreatePart(new Uri(relativePath, UriKind.Relative),
System.Net.Mime.MediaTypeNames.Application.Zip);
using (FileStream fs=fi.OpenRead()) {
CopyStream(fs, part.GetStream());
}
}
foreach (DirectoryInfo subDi in di.GetDirectories()) {
ZipDirectory(subDi,package);
}
}
private void CopyStream(Stream source, Stream target) {
const int bufferSize = 0x1000;
byte[] buf = new byte[bufferSize];
int bytesRead = 0;
while ((bytesRead = source.Read(buf, 0, bufferSize)) > 0) {
target.Write(buf, 0, bufferSize);
}
}