using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace Bowin.Common
{
///
/// UpLoad 的摘要说明。
///
public class UpLoad
{
public UpLoad()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool IsFileExist=false;
///
/// 文件上传
///
///
public string UpLoadFile(byte[] buffer ,string sFileName )
{
string filePath = System.Configuration.ConfigurationManager.AppSettings["__ImportDataFileUrl__"];
int iCounter = 0;
string downUrl = "";
FileManager fileManager = new FileManager();
string sEqualFileName = sFileName;
while ( true )
{
if (fileManager.IsFileExist (sEqualFileName))
{
iCounter++ ;
sEqualFileName = System.IO.Path.GetFileNameWithoutExtension(sFileName) + "(" + iCounter.ToString() + ")" +
System.IO.Path.GetExtension(sFileName);
}
else
{
sFileName = sEqualFileName;
break ;
}
}
if (!sFileName.Equals(""))
{
if (UpLoadToFileServer(buffer, sFileName))
{
downUrl = filePath + sFileName;
}
}
return downUrl;
}
//public string UpLoadFile(byte[] buffer, string sFileName)
//{
// string sFilePwd = "BBEFC0B4C3C5FE75391ACD4984635C6E";
// FileHandle.FileHandle upload = new DGDP.Bowin.Business.FileHandle.FileHandle();
// FileHandle.ResultOfString result = upload.Upload(sFilePwd, buffer, "/FSGIS/", sFileName);
// if (result.Code == 1)
// {
// return result.Detail;
// }
// else
// {
// return "";
// }
//}
///
/// 文件上传
///
public string UpLoadFile(HttpPostedFile fileControl , string sFileName)
{
string filePath = System.Configuration.ConfigurationManager.AppSettings["__ImportDataFileUrl__"];
int iCounter = 0;
string downUrl = "";
FileManager fileManager = new FileManager();
string sEqualFileName = sFileName;
while (true)
{
if (fileManager.IsFileExist(sEqualFileName))
{
iCounter++;
sEqualFileName = System.IO.Path.GetFileNameWithoutExtension(sFileName) + "(" + iCounter.ToString() + ")" +
System.IO.Path.GetExtension(sFileName);
}
else
{
sFileName = sEqualFileName;
break;
}
}
if (!sFileName.Equals(""))
{
if (UpLoadToFileServer(fileControl, sFileName))
{
downUrl = filePath + sFileName;
}
}
return downUrl;
}
///
/// 上传到文件服务器
/// update by :zqz 20090614
///
/// 上传控件
/// 上传路径
/// 文件名
/// bool值
private bool UpLoadToFileServer(HttpPostedFile fileControl, string fileName)
{
try
{
/*-----需要在web.config的AppSetting节点添加以下三个节点
*/
FileManager fileManager = new FileManager();
fileManager.UploadFile(fileControl.InputStream, fileName);
}
catch
{
return false;
}
return true;
}
///
/// 上传到文件服务器
///
/// 上传控件
/// 上传路径
/// 文件名
/// bool值
private bool UpLoadToFileServer(byte[] buffer,string fileName)
{
try
{
/*-----需要在web.config的AppSetting节点添加以下三个节点
*/
FileManager fileManager = new FileManager ();
return fileManager.UploadFile(buffer,fileName);
}
catch
{
return false;
}
}
}
}