在服务器中保存iamge(godaddy) [英] saving iamge in server(godaddy)

查看:93
本文介绍了在服务器中保存iamge(godaddy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i我正在使用此代码将数据保存在服务器(godaddy)中,但它没有将图像保存在我的应用程序的文件夹中,所以任何人都可以提供帮助请,



 [WebMethod] 
public static string SaveImageData( string value string remaining_data)
{
string fetchedData = value .Substring( value .IndexOf(' ,')+ 1 );
string str_ins_result = ;
// string strpath =E:\\Reconciliation_Files \\Recon_Files \\ + voID.Substring(2,2)+\\+ voID.Substring(4,2)+\\+ voID;
string strpath = 〜\\eAHD;

尝试
{
string [] methodDetails = fetchedData.Split(' ,');

string strID_Type_fileName = methodDetails [methodDetails.Length - 1 ];
string extension = strID_Type_fileName.Substring(strID_Type_fileName.LastIndexOf(' 。')+ 1 );

string fileContent = fetchedData.Substring( 0 ,fetchedData.LastIndexOf(< span class =code-string>' ,'));

byte [] data = Convert.FromBase64String(fileContent);
MemoryStream ms = new MemoryStream(data);


if (!Directory.Exists(strpath))
{
Directory.CreateDirectory(strpath) );
}

// 实例指向 $的文件流b $ b // 存储文件夹,使用原始文件名
// 命名生成的文件

FileStream fs = new FileStream(strpath + \\ + strID_Type_fileName,FileMode.Create );

string name_path = fs.Name.ToString();

str_ins_result = save_school_data(name_path,remaining_data);
// 写入包含原始内容的内存流
// 文件作为文件流的字节数组

尝试
{
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();

return str_ins_result;
}
catch (Exception ex_attachSave)
{
return 保存文件时引发异常,异常为: + ex_attachSave.Message;
}
}
catch (Exception exp)
{
// Response.Write(exp.ToString());
return 文件上传时引发异常,异常为: + exp.Message;
}
}

解决方案

尝试更改strpath:

  string  strpath =  〜\\\ \\ eAHD; 

To:

  string  strpath = Server.MapPath( 〜\\\\\\\\\ ); 

' 〜'是我的网站的根目录的IIS引用,并不直接适用于文件IO方法。

我还建议您使用Path.Combine而不是字符串连接:

 FileStream fs =  new  FileStream(Path.Combine(strpath,strID_Type_fileName),FileMode.Create); 


hi everyone,

i am using this code to save data in server(godaddy) but it is not saving image in my folder of this application so anyone can help me please,

[WebMethod]
   public static string SaveImageData(string value, string remain_data)
   {
       string fetchedData = value.Substring(value.IndexOf(',') + 1);
       string str_ins_result = "";
       //string strpath = "E:\\Reconciliation_Files\\Recon_Files\\" + voID.Substring(2, 2) + "\\" + voID.Substring(4, 2) + "\\" + voID;
       string strpath = "~\\eAHD";

       try
       {
           string[] methodDetails = fetchedData.Split(',');

           string strID_Type_fileName = methodDetails[methodDetails.Length - 1];
           string extension = strID_Type_fileName.Substring(strID_Type_fileName.LastIndexOf('.') + 1);

           string fileContent = fetchedData.Substring(0, fetchedData.LastIndexOf(','));

           byte[] data = Convert.FromBase64String(fileContent);
           MemoryStream ms = new MemoryStream(data);


           if (!Directory.Exists(strpath))
           {
               Directory.CreateDirectory(strpath);
           }

           // instance a filestream pointing to the
           // storage folder, use the original file name
           // to name the resulting file

           FileStream fs = new FileStream(strpath + "\\" + strID_Type_fileName, FileMode.Create);

           string name_path = fs.Name.ToString();

           str_ins_result = save_school_data(name_path, remain_data);
           // write the memory stream containing the original
           // file as a byte array to the filestream

           try
           {
               ms.WriteTo(fs);
               ms.Close();
               fs.Close();
               fs.Dispose();

               return str_ins_result;
           }
           catch (Exception ex_attachSave)
           {
               return "Exception raised while file saving, Exception is : " + ex_attachSave.Message;
           }
       }
       catch (Exception exp)
       {
           //Response.Write(exp.ToString());
           return "Exception raised while file uploading, Exception is : " + exp.Message;
       }
   }

解决方案

Try changing strpath:

string strpath = "~\\eAHD";

To:

string strpath = Server.MapPath("~\\eAHD");

'~' is an IIS reference for "root of my website" and isn't directly applicable to file IO methods.
I'd also suggest that you use Path.Combine instead of string concatenation:

FileStream fs = new FileStream(Path.Combine(strpath, strID_Type_fileName), FileMode.Create);


这篇关于在服务器中保存iamge(godaddy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆