2013-04-05 68 views
0

我想要的圖像存儲到兩個應用程序(在服務器上的發表)。這是我的代碼保存圖像:如何給服務器一個文件夾來保存圖像的路徑?

string path = Server.MapPath("/Images/Landing/bottom_banner/");   
string path1 = @"_http://10.241.193.22/Myapplication/Images/Landing/bottom_banner/"; 
    HttpPostedFileBase photo = Request.Files["adup"]; 
      if (photo.ContentLength != 0) 
      { 
       string lastPart = photo.FileName.Split('\\').Last(); 
       Random random = new Random(); 
       int rno = random.Next(0, 1000); 
       photo.SaveAs(path + rno + lastPart); 
       photo.SaveAs(path1 + rno + lastPart); 
      } 

注:Myapplication是託管在同一服務器上的其他應用程序

我的問題是我能夠使用Server.MapPath將圖像保存在我的第一個應用程序,但當編譯器來部分photo.SaveAs(path1 + rno + lastPart)它給出了一個錯誤:

The SaveAs method is configured to require a rooted path, and the path '_http://10.241.193.22/Myapplication/Images/Landing/bottom_banner/676Chrysanthemum.jpg' is not rooted

請建議我怎麼能消除這個問題呢?

+0

可能的重複http://stackoverflow.com/questions/1089713/httppostedfile-saveas-error-rooted-path – pascalhein 2013-04-05 12:25:19

+0

在這個問題上,人試圖只保存在一個應用程序中的文件。在這裏我試圖保存到兩個不同的應用 – nitinvertigo 2013-04-05 12:27:15

+0

仍然沒有在第一個答案給出解決辦法,請嘗試使用它爲你的情況 – pascalhein 2013-04-05 12:29:58

回答

1

我不確定這是否正確,但可以這樣做嗎?

在當前的應用程序商店的價值使用Server.Mappath,然後替換「MyApplication的」當前應用程序的名稱,然後添加尾部的路徑。像這樣的東西

string path1 = Server.MapPath(""); 
path1.Replace("Application1", "Myapplication"); //Considering "Application1" is the name of your current application 
path1 += "/Images/Landing/bottom_banner/"; 
HttpPostedFileBase photo = Request.Files["adup"]; 
     if (photo.ContentLength != 0) 
     { 
      string lastPart = photo.FileName.Split('\\').Last(); 
      Random random = new Random(); 
      int rno = random.Next(0, 1000); 
      photo.SaveAs(path1 + rno + lastPart); 
     } 

這可能是一個權限問題。我沒有檢查過它。如果它有效,請告訴我。

+0

上,我會試試這星期一,讓你知道,但我認爲它是正確的方式來做到這一點,它應該工作。無論如何,讓我知道,一旦我檢查 – nitinvertigo 2013-04-07 05:08:44

+0

Thx ..請讓我知道。 – pordi 2013-04-07 12:13:01

+0

雅這種技術正在工作 – nitinvertigo 2013-06-21 12:10:20

1

你應該張貼圖片到第二個服務器,並使用相同的方法(使用Server.Mappath)那裏。

這是不可能的,在遠程服務器上保存的圖像(或其它文件)。如果您知道絕對路徑(例如)'C:\ Web \ ApplicationOne ... \ image.png \'和'C:\ Web \ ApplicationTwo ... \ image.png',則可以替換路徑差異像這樣:

photo.SaveAs(path + rno + lastPart); 
photo.SaveAs(path.Replace("ApplicationOne", "ApplicationTwo") + rno + lastPart); 
+0

看到OP:「MyApplication的是託管*在同一臺服務器*上的其他應用程序」 – pascalhein 2013-04-05 12:28:22

+0

兩個應用程序在同一臺服務器 – nitinvertigo 2013-04-05 12:32:16

相關問題