2016-10-17 93 views
-1

我有我自己的服务器与本地IP为172.23.1.66在CentOS 7C#保存PictureBox的Image到远程服务器

所以在我的计划,我可以用我的字符串imageLocation =“http://172.23.1.66/img/978979892782.jpg”服务器调用图像;

在其他情况下,我想将它保存到我的远程服务器。我无法在Windows资源管理器中访问它,我只能在浏览器上访问它。我使用WinSCP远程控制它。

我尝试这样的:

picImage.Image.Save(@"\\172.23.1.66\img\" + clsLibrary.throwCode + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); // throwCode is my file name 

但它扔型 'System.Runtime.InteropServices.ExternalException' 未处理的异常发生在System.Drawing.dll程序

我也有请尝试删除第一个IP中的\\

一切都会失败,任何人都可以帮忙吗?

+0

后写图像到一个临时文件中,然后使用[SFTP]发送它(http://blog.deltacode.be/2012/01/05/uploading-a-file-使用-sftp-in-c-sharp /) – Martheen

+0

你可以编写一个小型的C++或python服务器,你可以从c#程序发送一个图像文件缓冲区,并在接收到它之后,服务器程序会将它保存到你给定的路径 –

回答

0

使用服务器的MapPath以确保您可以使用您的网址您的服务器上:

picImage.Image.Save(Server.MapPath("~/img/") + clsLibrary.throwCode + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
+0

它给我看一个错误**当前上下文中不存在“服务器”名称** –

+0

请尝试此操作:System.Web.HttpContext.Current.Server.MapPath。 –

+0

那么现在我有这个错误**名称空间'System.Web'中不存在类型或名称空间名称'HttpContext'(你是否缺少程序集引用?)** ..我不知道发生了什么,我已经尝试**使用System.Web; **并使用您的代码,但我仍然得到相同的错误。我正在使用Visual Studio 2015,现在我的代码是这样的** picImage.Image.Save(System.Web.HttpContext.Current.Server.MapPath(“172.23.1.66/img/”)+ clsLibrary.throwCode +“.jpg “,System.Drawing.Imaging.ImageFormat.Jpeg); **发生了什么? –

0

- 你只被允许使用IP address.To保存图片的IP获取图片地址等

public string TEMP_PATH = "~/Temp/ImagesPath/"; 

确保您有适当的权限访问/ Temp/ImagesPath /。

try 
     { 
      FileInfo fileDatails = new FileInfo(AsyncImageUpload.PostedFile.FileName);/* here you can get file using you source like OFD or FileUpload Controls */ 
      string exten = fileDatails.Extension; 
      Stream fs = this.AsyncImageUpload.FileContent; 
      BinaryReader br = new BinaryReader(fs); 
      Byte[] bytes = br.ReadBytes((Int32)fs.Length); /* convert file to byte */ 
      String Base64file = Convert.ToBase64String(bytes); 
      destinationPath = Server.MapPath(TEMP_PATH + fileDatails.Name); 
      Byte[] frombytes = Convert.FromBase64String(Base64file); 
      File.WriteAllBytes(destinationPath, frombytes); /*write file to destination folder on server */ 
     } 
     catch (Exception exp) 
     { 
      throw exp; 
     } 
+0

需要http://或只是我的IP?我有一个访问〜/ img /使用WinSCP –

+0

什么是文件变量声明?那是流文件吗? –

+0

hi Bowi ...请参阅更新的代码。不需要提及http://或IP。相反,声明公共字符串TEMP_PATH =“〜/ img /”;如果你的应用程序也运行在同一个远程服 –