2010-08-27 427 views
6

我在網站中使用Image.FromStream方法時遇到了困難。下面的代碼在我的電腦上完美運行。但是當我將它上傳到測試服務器時,它總是給我「參數無效」異常。System.Drawing.Image.FromStream()方法中的「參數無效」異常

if (!afuImageFile.IsUploading && afuImageFile.HasFile) 
{ 
    System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent); 
} 

afuImageFile是Ajax工具箱的AsynFileUploader控制。 afuImageFile.FileContentHttpInputStream。我想我需要給某個文件夾添加一些權限。誰能幫我?

+0

聽起來像這個問題類似的問題。 http://stackoverflow.com/questions/1614773/image-fromstreampostedfile-inputstream-fails-parameter-is-not-valid-async – NewfrontSolutions 2015-11-09 13:59:46

回答

2

請確保您的FileContent流作爲其位置設置爲0。

否則,您可能要停用圖像驗證通過改變呼叫:

System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent); 

到:

System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent, true, false); 

請參閱Image.FromStream檢查其他重載。