开发者

Saving a file to a user-created folder

I have (more or less) the following code:

private static void SaveFolder(MyFolder folder, string location)
{
  string folderName = Path.Combine(location, folder.Name);
  DirectoryInfo di = Directory.CreateDirectory(folderName);
  foreach ( MyFile childItem in folder.Children )
  {
    string fileName = Path.Combine(di.FullName, childItem.Name);
    byte[] payload = GetFilePayload(childItem);
    File.WriteAllBytes(fileName, payload);
  }
}

The application is an office add-in, running under a user that is admin on the machine (WinXP)

开发者_开发知识库I create the folder without problems, however when I create the files (File.WriteAllBytes line) I get a UnauthorizedAccessException.

Why can't I save file in a folder I just created?


Sorry, folks, it was a stupid bug in some other code, that essentially transformed

File.WriteAllBytes(fileName, payload);

into

File.WriteAllBytes(folderName, payload);

:(

The OS was trying to save a file with the same name as the folder, and the WTF is the exception I was receiving, that send me on a tangent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜