正如我们平时在网上下载一些有用的视频课件.压缩文件.word文档等.
这个功能如何用c#实现啊?有没有特别的函数?望赐教.谢谢
这个功能如何用c#实现啊?有没有特别的函数?望赐教.谢谢
解决方案 »
- 如何控制C#开发的程序只能试用一个月?
- .Net 调试问题
- webBrowser控件如何直接显示word文档,而不是在本地的word程序中打开?
- 系统有将一个string[]中从第n个元素复制到第m个元素到另一个string[]中吗?
- 一个关于直接调用Interop.CDO.dll组件生成MHT文件,出现的问题
- usercontrol
- 如何判断某一文本是否为日期类型
- 为什么mycmd.ExecuteNonQuery() 返回值总是-1呢??帮忙
- owc 11柱状图问题
- 如何获取当前光标座标?
- 怎样手工释放byte数组变量占用的内存?
- 引用动态库的时候提示“请确保此文件可访问并且是一个有效的程序集或COM组建”
http://dotnet.aspx.cc/ShowDetail.aspx?id=58EA3515-36F2-4FD9-AC89-EAF49F59816C ;
另一种写到数据库的方法是我自己写的请参考吧:上传和下载都有:上传为:
string FileName="";
int pos=0;
if (this.filename.PostedFile!=null)
{
FileName=this.filename.PostedFile.FileName.ToString();
pos=FileName.LastIndexOf("\\");
FileName=FileName.Substring(pos+1,FileName.Length-pos-1);
Byte[] photo=new byte[this.filename.PostedFile.ContentLength];
this.filename.PostedFile.InputStream.Read (photo,0,this.filename.PostedFile.ContentLength);
cEmsAttachmentsEntity cAe = new cEmsAttachmentsEntity();
cAe.OperationId=Request["OperationId"].ToString();
cAe.OpSeqNum=Request["OperationId"].ToString();
cAe.Name =this.AttName.Value.ToString().Trim();
cAe.DocExplain =this.AttExplain.Value.ToString().Trim();
cAe.Property ="0";
cAe.FileName=FileName;
cAe.Entity=photo;
cEmsAttachments.AddAttachments(cAe);
Response.Redirect("AddDocument.aspx?OperationId="+Request["OperationId"],false);
下载为:byte[] photo=new byte[0];
string OperationId=this.Request["OperationId"].ToString();
string FileName="";
SqlConnection Conn = new SqlConnection(cEmsDataConnString.EMonitor);
SqlCommand logoCMD = new SqlCommand("select FileName,Entity from OP_Attachments where OperationId="+OperationId, Conn);
Conn.Open();
SqlDataReader myReader = logoCMD.ExecuteReader(CommandBehavior.SequentialAccess); int bufferSize = 100; // Size of the BLOB buffer.
byte[] outbyte = new byte[bufferSize]; // The BLOB byte[] buffer to be filled by GetBytes.
long retval; // The bytes returned from GetBytes.
long startIndex = 0; // The starting position in the BLOB output. //string pub_id = ""; // The publisher id to use in the file name.
this.Response.Clear();
this.Response.ContentType="application/x-msdownload";
this.Response.ContentEncoding = Encoding.Default;
while (myReader.Read())
{
// Get the publisher id, which must occur before getting the logo.
FileName = myReader.GetString(0);
//this.Response.AddHeader("Content-disposition","attachment;StencilName="+ Encoding.Default.GetString(Encoding.Unicode.GetBytes(StencilName)));
this.Response.AddHeader("Content-disposition","attachment;filename="+ HttpUtility.UrlEncode(FileName));
// Read the bytes into outbyte[] and retain the number of bytes returned.
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
this.Response.BinaryWrite(outbyte); // Continue reading and writing while there are bytes beyond the size of the buffer.
while (retval == bufferSize)
{
// Reposition the start index to the end of the last buffe0r and fill the buffer.
startIndex += bufferSize;
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
this.Response.BinaryWrite(outbyte);
}
}
this.Response.End() ; // Close the reader and the connection.
myReader.Close();
Conn.Close();
如果是http或者ftp的,你可以用webclient或者用socket去写webclient的话,你可以参看msdn的例子;而用socket的话,你可以去网上找找例子,例如:
http://www.codeproject.com/csharp/ftp.asp