还是我自己解决了!using System;
using System.IO;namespace UploadFile
{
interface IUploadFile
{
void UploadFile();//接口,上传文件。
}
public class TUploadFile:IUploadFile
{
string Src = "";
string Dest = "";
string DestName = "";
bool IsOverWrite = false;
public TUploadFile(string StrSrc)//一个参数,上传StrSrc到根目录下,保持原文件名。
{
this.Src = StrSrc;
this.Dest = @"./";
this.DestName = Path.GetFileName(this.Src);
this.IsOverWrite = false;
}
public TUploadFile(string StrSrc,string StrDes,string StrDesName,bool OverWrite)//参数分别是源文件名,目标地址,目标文件名,是否重写
{
this.Src = StrSrc;
this.Dest = StrDes;
this.DestName = StrDesName;
this.IsOverWrite = OverWrite;
}
public TUploadFile(string StrSrc,string StrDes,bool OverWrite)//保持原文件名
{
this.Src = StrSrc;
this.Dest = StrDes;
this.DestName = Path.GetFileName(this.Src);
this.IsOverWrite = OverWrite;
}
public TUploadFile(string StrSrc,string StrDes)
{
this.Src = StrSrc;
this.Dest = StrDes;
this.DestName = Path.GetFileName(this.Src);
this.IsOverWrite = false;
}
public string PDestName
{
get{return this.DestName;}
set{this.DestName = value;}
}
public string PSrc
{
get
{
return this.Src;
}
set
{
this.Src = value;
}
}
public string PDest
{
get{return this.Dest;}
set{this.Dest = value;}
}
public bool POverWrite
{
get{return this.IsOverWrite;}
set{this.IsOverWrite = value;}
}
public void UploadFile()
{
if (!this.IsOverWrite)
{
if(File.Exists(this.Src))
throw(new Exception("文件已经存在!"));
}
File.Copy(this.Src,System.Web.HttpContext.Current.Server.MapPath(this.Dest)+this.DestName,this.IsOverWrite);
}
}
}
using System.IO;namespace UploadFile
{
interface IUploadFile
{
void UploadFile();//接口,上传文件。
}
public class TUploadFile:IUploadFile
{
string Src = "";
string Dest = "";
string DestName = "";
bool IsOverWrite = false;
public TUploadFile(string StrSrc)//一个参数,上传StrSrc到根目录下,保持原文件名。
{
this.Src = StrSrc;
this.Dest = @"./";
this.DestName = Path.GetFileName(this.Src);
this.IsOverWrite = false;
}
public TUploadFile(string StrSrc,string StrDes,string StrDesName,bool OverWrite)//参数分别是源文件名,目标地址,目标文件名,是否重写
{
this.Src = StrSrc;
this.Dest = StrDes;
this.DestName = StrDesName;
this.IsOverWrite = OverWrite;
}
public TUploadFile(string StrSrc,string StrDes,bool OverWrite)//保持原文件名
{
this.Src = StrSrc;
this.Dest = StrDes;
this.DestName = Path.GetFileName(this.Src);
this.IsOverWrite = OverWrite;
}
public TUploadFile(string StrSrc,string StrDes)
{
this.Src = StrSrc;
this.Dest = StrDes;
this.DestName = Path.GetFileName(this.Src);
this.IsOverWrite = false;
}
public string PDestName
{
get{return this.DestName;}
set{this.DestName = value;}
}
public string PSrc
{
get
{
return this.Src;
}
set
{
this.Src = value;
}
}
public string PDest
{
get{return this.Dest;}
set{this.Dest = value;}
}
public bool POverWrite
{
get{return this.IsOverWrite;}
set{this.IsOverWrite = value;}
}
public void UploadFile()
{
if (!this.IsOverWrite)
{
if(File.Exists(this.Src))
throw(new Exception("文件已经存在!"));
}
File.Copy(this.Src,System.Web.HttpContext.Current.Server.MapPath(this.Dest)+this.DestName,this.IsOverWrite);
}
}
}
解决方案 »
- C#线程怎么调用带有参数和返回值的方法,在线等~~~
- winform选项卡问题
- 如何捕捉鼠标在自定义控件之外单击或者双击
- String 和 StringBuilder 的区别和使用环境?
- 新手提问 急 请进datagridview
- C#中有类似于BCB中的FindDialog 的控件吗?
- 请问在.net中做一个Flash播放器要用到哪个播放控件
- 高手指点:怎样用MdiaPlay9.0读写Access的媒体文件(音乐) 急!!!!急!!!!急!!!!
- WinForm增删改如何刷新DataGridView数据
- 在ASP.NET(C#)中如何创建柱状图和饼状图?
- 软件自动升级~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 我使用.net打印,边距设置不管用,如何办? --在线急候!!
2。如果要把本地文件传到服务器上应该使用
public byte[] UploadFile(string address,string fileName);
方法。