裸体跪求各位大哥大姐,进来看下嘛!
在WebService中,怎么加压一个文件?怎么下载一个文件,我应该用什么数据类型来接受它?在WinForm中,怎么对其解压??
谢谢了!!急用!! --------------------编程问答-------------------- 在WebService 中又不能用Response 所以就不知道怎么办了。。。。?
谢谢各位大哥大姐的指点!!! --------------------编程问答-------------------- 帮顶! --------------------编程问答--------------------
--------------------编程问答-------------------- 把文件转化为 2进制流
/// <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
大哥! --------------------编程问答-------------------- 自己写算法 压缩解压,实在不愿意的话 介绍你一个方法:安装完 winrar后 在安装目录下有个 dos 下的压缩解压工具 功能很强大 可以压缩 或者加密等 具体看帮助吧。(文件名就是 Rar.exe)
补充:.NET技术 , C#