裸体跪求各位大哥大姐,进来看下嘛! 在WebService 中又不能用Response 所以就不知道怎么办了。?谢谢各位大哥大姐的指点!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 分块上传文件 /// </summary> /// <param name="bt"></param> /// <param name="fileName"></param> /// <param name="oldFileName"></param> /// <returns></returns> [WebMethod(Description="上传附件")] public bool AttachUpLoad1(byte[] bt,string fileName,string oldFileName) { string attachPath=System.Configuration.ConfigurationSettings.AppSettings["AttachPath"]; string filePath=Server.MapPath(attachPath); filePath=filePath+"\\"; string fileName1=fileName.Substring(0,4); string fileName2=fileName.Substring(0,8); int a=oldFileName.LastIndexOf("."); string fileType=oldFileName.Substring(a); string strDateFileName=""; FileStream fs=null; try { if (!Directory.Exists(filePath+fileName1)) { Directory.CreateDirectory(filePath+fileName1); } if(!Directory.Exists(filePath+fileName1+"\\"+fileName2)) { Directory.CreateDirectory(filePath+fileName1+"\\"+fileName2); } strDateFileName = filePath+fileName1+"\\"+fileName2+"\\"+fileName+fileType; //文件不存在 if(!File.Exists(strDateFileName)) { fs = new FileStream(strDateFileName,FileMode.Create,FileAccess.Write,FileShare.None); } else { fs = new FileStream(strDateFileName,FileMode.Append,FileAccess.Write,FileShare.None); } fs.Write(bt, 0, bt.Length); fs.Close(); bt=null; fs=null; return true; } catch(Exception ex) { bt=null; fs=null; return false; } } 把文件转化为 2进制流 然后的调用 WebService 的方法 AttachUpLoad1();第一个参数是 2进制流的文件 后面的是服务器的文件名和 文件以前的名字 #region 下载附件 /// <summary> /// 读取的文件 /// </summary> /// <param name="fileName">日期文件名</param> /// <returns>读取的文件字节数组</returns> [WebMethod(Description="下载附件")] public byte[] AttachDownLoad(string fileName) { string filePath=System.Configuration.ConfigurationSettings.AppSettings["AttachPath"]; filePath=Server.MapPath(filePath)+"\\"; string fileName1=fileName.Substring(0,4); string fileName2=fileName.Substring(0,8); try { FileStream fs=new FileStream(filePath+fileName1+"\\"+fileName2+"\\"+fileName,FileMode.Open); long i=fs.Length; byte[] b=new byte[i]; fs.Read(b,0,b.Length); fs.Close(); fs=null; return b; } catch(Exception ex) { Console.Write(ex.ToString()); return null; } } #endregion 自己写算法 压缩解压,实在不愿意的话 介绍你一个方法:安装完 winrar后 在安装目录下有个 dos 下的压缩解压工具 功能很强大 可以压缩 或者加密等 具体看帮助吧。(文件名就是 Rar.exe) 关于EXT上传图片的问题 asp.net 网页中点击一个按钮,页面左下角有个错误三角 C#中怎么用文本文档保存DataGridView中的信息 谁帮我解释一下C#中的CreateObject()方法。 vs.net中的textbox控件,在鼠标 按下光标总是最前面,无法地位到想要的位置 求myexcel实现dataset保存excel的方法 一个很奇怪的问题? 播放器 帮忙救救急 C# 可以用什么做中间件?? c#系统调试运行时会僵死?连Microsoft Visual Studio .NET 2005也会一并僵死?为什么,100分 水晶报表winform图片显示不清楚?
/// <summary>
/// 分块上传文件
/// </summary>
/// <param name="bt"></param>
/// <param name="fileName"></param>
/// <param name="oldFileName"></param>
/// <returns></returns>
[WebMethod(Description="上传附件")]
public bool AttachUpLoad1(byte[] bt,string fileName,string oldFileName)
{
string attachPath=System.Configuration.ConfigurationSettings.AppSettings["AttachPath"]; string filePath=Server.MapPath(attachPath);
filePath=filePath+"\\";
string fileName1=fileName.Substring(0,4);
string fileName2=fileName.Substring(0,8);
int a=oldFileName.LastIndexOf(".");
string fileType=oldFileName.Substring(a);
string strDateFileName=""; FileStream fs=null;
try
{ if (!Directory.Exists(filePath+fileName1))
{
Directory.CreateDirectory(filePath+fileName1);
}
if(!Directory.Exists(filePath+fileName1+"\\"+fileName2))
{
Directory.CreateDirectory(filePath+fileName1+"\\"+fileName2);
}
strDateFileName = filePath+fileName1+"\\"+fileName2+"\\"+fileName+fileType; //文件不存在
if(!File.Exists(strDateFileName))
{
fs = new FileStream(strDateFileName,FileMode.Create,FileAccess.Write,FileShare.None);
}
else
{
fs = new FileStream(strDateFileName,FileMode.Append,FileAccess.Write,FileShare.None);
}
fs.Write(bt, 0, bt.Length);
fs.Close();
bt=null;
fs=null;
return true;
}
catch(Exception ex)
{
bt=null;
fs=null;
return false;
}
}
然后的调用 WebService 的方法 AttachUpLoad1();
第一个参数是 2进制流的文件 后面的是服务器的文件名和 文件以前的名字
#region 下载附件
/// <summary>
/// 读取的文件
/// </summary>
/// <param name="fileName">日期文件名</param>
/// <returns>读取的文件字节数组</returns>
[WebMethod(Description="下载附件")]
public byte[] AttachDownLoad(string fileName)
{
string filePath=System.Configuration.ConfigurationSettings.AppSettings["AttachPath"];
filePath=Server.MapPath(filePath)+"\\";
string fileName1=fileName.Substring(0,4);
string fileName2=fileName.Substring(0,8);
try
{
FileStream fs=new FileStream(filePath+fileName1+"\\"+fileName2+"\\"+fileName,FileMode.Open);
long i=fs.Length;
byte[] b=new byte[i];
fs.Read(b,0,b.Length);
fs.Close();
fs=null;
return b;
}
catch(Exception ex)
{
Console.Write(ex.ToString());
return null;
}
}
#endregion