ここ数時間、Googleとstackoverflowを本当によく使用しましたが、問題を解決するのに役立つ解決策やトピックが見つかりませんでした.
タスクと問題:
ローカルマシンで完全に動作する ASP.NET Web フォームを作成しました。これにより、ユーザーは Dynamics CRM 2011 で顧客を作成できます。次に、ユーザーは注釈を顧客に追加し、アップロードするファイルを追加できます。
次のステップは、IIS7 でこの Web フォームを発行することです。これにより、リモートの Windows 2008 R2 サーバー上にあるリモートでアクセスできるようになります。ここで Web フォームをテストし、FileUpload コントロールからデータを選択すると、IIS7 は正しい Path(FileNotFoundException)
を取得しません。サーバーから直接ファイルを「アップロード」したい場合でも、データからの Filepath ではなく、常にルート ディレクトリを使用します。 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);
}
誰かがこれで私を助けてくれることを願っています。たぶん、ほんの少しの構成か、アーキテクチャ全体の控えめな表現が間違っているに違いありません。