【发布时间】:2012-12-22 04:53:08
【问题描述】:
过去几个小时我确实经常使用 google 和 stackoverflow,但我没有找到帮助我解决问题的解决方案或主题。
任务和问题:
我创建了一个 ASP.NET Webform,它可以在我的本地机器上完美运行。它允许用户在 Dynamics CRM 2011 中创建客户。在此旁边,用户可以向客户添加注释并添加要上传的文件。
下一步是在 IIS7 上发布此 Webform,以便您可以在远程 Windows 2008 R2 服务器上远程访问它。如果我现在测试 Webform 并从 FileUpload 控件中选择一个数据,IIS7 没有得到正确的路径(FileNotFoundException),它总是使用他的根目录而不是数据中的文件路径,即使我想直接“上传”一个文件从安装 IIS 的服务器。
堆栈跟踪:
[FileNotFoundException: Die Datei "c:\windows\system32\inetsrv\test.txt" konnte nicht gefunden werden.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12898679
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +2481
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +229
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +102
System.IO.File.OpenRead(String path) +55
FirstWebform._Default.create_Button_Click(Object sender, EventArgs e) in C:\Users\flah\Documents\Visual Studio 2010\Projects\FirstWebform\FirstWebform\Main.aspx.cs:86
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
我尝试过的:
我已经读到我必须将 IIS7 上的文件保存在带有
FileUpload.Saveas("C:\\folder\\" + FileUpload.Filename)的临时目录中,然后才能使用它 但同样的问题发生了,文件路径错误,它没有得到它。我尝试通过
Path.GetFullPath(FileUploadControl.PostedFile.FileName);获取路径名,但也没有用 - 与Server.MapPath();相同我已经为服务器上的用户设置了权限
我不明白为什么 IIS 总是将他的根目录用于 FileUpload,以及为什么它在我的本地机器上运行良好。
没有我尝试的重要代码:
if (FileUpload1.HasFile)
{
FileStream stream = File.OpenRead(FileUpload1.PostedFile.FileName);
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);
stream.Close();
//Dynamics CRM 2011 upload
string encodedData = System.Convert.ToBase64String(byteData);
newAnnotation.DocumentBody = encodedData;
EntityReference refNote = new EntityReference();
refNote.LogicalName = "account";
refNote.Id = newAccountId;
newAnnotation.Attributes.Add("objectid", refNote);
service.Create(newAnnotation);
} else {
EntityReference refNote = new EntityReference();
refNote.LogicalName = "account";
refNote.Id = newAccountId;
newAnnotation.Attributes.Add("objectid", refNote);
service.Create(newAnnotation);
}
我希望有人可以帮助我解决这个问题。也许它只是一个小配置或者我对整个架构的轻描淡写一定是错误的。
【问题讨论】:
标签: c# asp.net file-upload iis-7 dynamics-crm-2011