上传.rar到文件夹,有此文件夹则上传,没有自动生成
上传类:
public class UpFile
{
public UpFile()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void CreateDir(string DirectoryName, String Root)
{
string DirPath = Root + "\\ " + "software " + "\\ " + DirectoryName;
if (!Directory.Exists(DirPath)) //如果文件夹不存在则创建
{
Directory.CreateDirectory(DirPath);
}
}
public static string UpLoadFile(System.Web.UI.WebControls.FileUpload UpLoadsoftFile, string Path) //控制图片大小
{
string fullFileName = UpLoadsoftFile.PostedFile.FileName;//文件全名
//string fileName = UpLoadsoftFile.PostedFile.FileName.Substring(fullFileName.LastIndexOf( "\\ ") + 1);//文件名
string fileType = UpLoadsoftFile.PostedFile.FileName.Substring(fullFileName.LastIndexOf( ". ") + 1);//后缀名
string FileName = DateTime.Now.ToString( "yyyyMMddHHmmss ") + ".rar ";
if (fileType.ToLower() == "rar ")
{
UpLoadsoftFile.SaveAs(Path + "\\ " + FileName);
return FileName;
}
else
{
return FileName = " ";
}
}
public static void DeleteFile(string FileName, string Path)
{
string path = Path + "\\ " + FileName;
if (File.Exists(path))
{
File.Delete(path);
}