2016-08-15 10 views
1

私はバナー画像を保存しようとしています。フォルダに保存する前に、それぞれのフォルダもチェックして作成していますが、チェックしてもエラーになりますフォルダが存在することを示します。コードは次のとおりです。パスの一部を見つけることができませんでした:Server.mapPath

HttpPostedFileBase banner = Request.Files["banner"]; 
if (banner != null && banner.ContentLength > 0) { 
    var folder = Server.MapPath("~/images/Continents/"); 
    if (!Directory.Exists(folder)) { 
     Directory.CreateDirectory(folder); 
    } 
    banner.SaveAs(Server.MapPath("~/images/Continents/" + image.FileName)); 
    string x = "/images/Continents/" + image.FileName; 
    continent.BANNER = x; 
} 

私には紛失しているものがありますか?

+0

どの行でエラーを得ていますか? 'SaveAs'? – Shyju

+0

の 'image'オブジェクトは何ですか?それはどこから来ていますか? – Shyju

+0

私はこれが少しこの質問の重複していると思う[これを試してください](http://stackoverflow.com/questions/16357839/server-mappath-could-not-find-a-part-of-the-path-in- asp-net) – Ramki

答えて

1

次のようにPath.Combine()を使用し、Server.MapPathでパスを連結する:

banner.SaveAs(Server.MapPath(Path.Combine("~/images/Continents", image.FileName))); 
+0

私はこのコードを使用しました: 'banner.SaveAs(Server.MapPath(Path.Combine( "〜/ images/Continents /" + image.FileName))); ' – JackXandar

+0

でも同じ回答が表示されます – JackXandar

+0

例外の詳細:System.UnauthorizedAccessException:' c:¥users¥amir¥documents¥visual studio 2013¥Projects¥SevenZones¥SevenZones¥images¥Continents 'のパスへのアクセスが拒否されました。 – JackXandar

関連する問題