FileUpload 上传文件,并实现c#使用Renci.SshNet.dll实现SFTP文件传输
fileupload上传文件和jquery的uplodify控件使用方法类似,对服务器控件不是很熟悉,记录一下。
主要是记录新接触的sftp文件上传。服务器环境下使用freesshd搭建好环境后,windos环境下可视化工具filezilla可#以很容易实现文件的传输。
本例中主要是c#使用Renci.SshNet.dll实现SFTP文件传输。
代码如下:
protected void btnExcelImport_Click(object sender, EventArgs e)
{
if (this.LogisticsUpload.HasFile)//判断是否存在上传文件
{
string filename = this.LogisticsUpload.PostedFile.FileName;
string extension = (new FileInfo(filename)).Extension;
string newfilename = System.DateTime.Now.ToString("yyyyMMddHHmmss") + extension;
//判断是否存在上传路径,如果不存在,则创建
if (!Directory.Exists(Server.MapPath("../Upload/Logistics")))
{
Directory.CreateDirectory(Server.MapPath("../Upload/Logistics"));
}
string path = Server.MapPath("../Upload/Logistics/");
this.LogisticsUpload.PostedFile.SaveAs(path + newfilename);//这一步实现上传文件
//插入数据库表
LogisticsLog logmodel = new LogisticsLog();
logmodel.FileName = filename;
logmodel.SavePath = path;
logmodel.CreateTime = DateTime.Now;
logmodel.CreaterId = base.CurrentUser.UserID.ToString();
logmodel.AgentId = this.AgentDropDownList.SelectedItem.Value.ToInt();
logmodel.AgentName = this.AgentDropDownList.SelectedItem.Text.ToString();
logmodel.Status = Convert.ToInt32(Core.EnumDefine.LogisticsStatus.wait);
//通过sftp方式上传到服务器
string sftppath = "/" + filename;//sftp根目录加上存入文件名
string localpath = path + newfilename;//本地文件
Framework.Common.SFTPOperation sftp = new Framework.Common.SFTPOperation(Config.ConfigSettings.Instance.SAP_SFTP_SERVER, int.Parse(Config.ConfigSettings.Instance.SAP_SFTP_PORT), Config.ConfigSettings.Instance.SAP_SFTP_ACCOUNT, Config.ConfigSettings.Instance.SAP_SFTP_PASSWORD);
sftp.Connect();
sftp.Put(localpath, sftppath);
sftp.Disconnect();
LogisticsBusinessService log = new LogisticsBusinessService();
if (log.Add(logmodel))
{
//Response.Write("<script>window.open('StockBatchList.aspx','_self')</script>");
this.AlertMessage("上传成功!");
Response.Redirect("LogisticsList.aspx");
}
else
{
this.AlertMessage("上传失败!");
}
}
}
sftp操作类,用到的方法已经标黄,直接看,主要是put方法
public class SFTPOperation
{
#region 字段或属性
/// <summary>
/// sftp连接
/// </summary>
private SftpClient sftp;
/// <summary>
/// SFTP连接状态
/// </summary>
public bool Connected { get { return sftp.IsConnected; } }
/// <summary>
/// 主机地址
/// </summary>
private const string HOST = "192.168.0.80";//192.168.0.80 //140.231.210.125
/// <summary>
/// 端口
/// </summary>
private const int PORT = 22;
/// <summary>
/// 用户名
/// </summary>
private const string USERNAME = "siemens_sftp";//siemens_sftp //sie_icit
/// <summary>
/// 密码
/// </summary>
private const string PASSWORD = "password01!";//password01! //Icitsftp20140826+-
#endregion
#region 构造
/// <summary>
/// 构造
/// </summary>
public SFTPOperation()
{
var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(USERNAME);
keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs)
{
foreach (var prompt in eventArgs.Prompts)
{
if (prompt.Request.Equals("Password: ",
StringComparison.InvariantCultureIgnoreCase))
{
prompt.Response = PASSWORD;
}
}
};
var passwordAuthMethod = new PasswordAuthenticationMethod(USERNAME, PASSWORD);
var connInfo = new ConnectionInfo(HOST, USERNAME, new AuthenticationMethod[] {
passwordAuthMethod,
keyboardAuthMethod
});
sftp = new SftpClient(connInfo);
//sftp = new SftpClient(HOST, PORT, USERNAME, PASSWORD);
}
/// <summary>
/// 构造
/// </summary>
/// <param name="host">主机</param>
/// <param name="port">端口</param>
/// <param name="user">用户名</param>
/// <param name="pwd">密码</param>
public SFTPOperation(string host, int port, string user, string pwd)
{
var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(user);
keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs)
{
foreach (var prompt in eventArgs.Prompts)
{
if (prompt.Request.Equals("Password: ",
StringComparison.InvariantCultureIgnoreCase))
{
prompt.Response = pwd;
}
}
};
var passwordAuthMethod = new PasswordAuthenticationMethod(user, pwd);
var connInfo = new ConnectionInfo(host, user, new AuthenticationMethod[] {
passwordAuthMethod,
keyboardAuthMethod
});
sftp = new SftpClient(connInfo);
//sftp = new SftpClient(host, port, user, pwd);
}
#endregion
#region 连接SFTP
/// <summary>
/// 连接SFTP
/// </summary>
/// <returns>true成功</returns>
public bool Connect()
{
try
{
if (!Connected)
{
sftp.Connect();
}
return true;
}
catch (Exception ex)
{
throw new Exception(string.Format("连接SFTP失败,原因:{0}", ex.Message));
}
}
#endregion
#region 断开SFTP
/// <summary>
/// 断开SFTP
/// </summary>
public void Disconnect()
{
try
{
if (sftp != null && Connected)
{
sftp.Disconnect();
}
}
catch (Exception ex)
{
throw new Exception(string.Format("断开SFTP失败,原因:{0}", ex.Message));
}
}
#endregion
#region SFTP上传文件
/// <summary>
/// SFTP上传文件
/// </summary>
/// <param name="localPath">本地路径</param>
/// <param name="remotePath">远程路径</param>
public void Put(string localPath, string remotePath)
{
try
{
using (var file = File.OpenRead(localPath))
{
sftp.UploadFile(file, remotePath);
}
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件上传失败,原因:{0}", ex.Message));
}
}
/// <summary>
/// SFTP上传文件
/// </summary>
/// <param name="stream">文件流</param>
/// <param name="remotePath">远程路径</param>
public void Put(Stream stream, string remotePath)
{
try
{
Connect();
sftp.UploadFile(stream, remotePath);
Disconnect();
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件上传失败,原因:{0}", ex.Message));
}
}
#endregion
#region SFTP获取文件
/// <summary>
/// SFTP获取文件
/// </summary>
/// <param name="remotePath">远程路径</param>
/// <param name="localPath">本地路径</param>
public void Get(string remotePath, string localPath)
{
try
{
var byt = sftp.ReadAllBytes(remotePath);
File.WriteAllBytes(localPath, byt);
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件获取失败,原因:{0}", ex.Message));
}
}
public void DownloadFile()
{
//sftp.DownloadFile()
}
#endregion
#region 删除SFTP文件
/// <summary>
/// 删除SFTP文件
/// </summary>
/// <param name="remotePath">远程路径</param>
public void Delete(string remotePath)
{
try
{
sftp.Delete(remotePath);
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件删除失败,原因:{0}", ex.Message));
}
}
/// <summary>
/// 删除SFTP文件
/// </summary>
/// <param name="remoteFile">远程路径</param>
public void DeleteFile(string remoteFile)
{
try
{
Connect();
sftp.DeleteFile(remoteFile);
Disconnect();
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件删除失败,原因:{0}", ex.Message));
}
}
#endregion
#region 获取SFTP文件列表
/// <summary>
/// 获取SFTP文件列表
/// </summary>
/// <param name="remotePath">远程目录</param>
/// <param name="fileSuffix">文件后缀</param>
/// <returns></returns>
public ArrayList GetFileList(string remotePath, string fileSuffix)
{
try
{
fileSuffix = fileSuffix.ToUpper();
var files = sftp.ListDirectory(remotePath);
var objList = new ArrayList();
foreach (var file in files)
{
if (file.IsDirectory) continue;
string name = file.Name.ToUpper();
if (name.Length > (fileSuffix.Length + 1) && fileSuffix == name.Substring(name.Length - fileSuffix.Length))
{
objList.Add(file.FullName);
}
}
return objList;
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件列表获取失败,原因:{0}", ex.Message));
}
}
#endregion
#region 移动SFTP文件
/// <summary>
/// 移动SFTP文件
/// </summary>
/// <param name="oldRemotePath">旧远程路径</param>
/// <param name="newRemotePath">新远程路径</param>
public void Move(string oldRemotePath, string newRemotePath)
{
string fileName = string.Empty;
try
{
newRemotePath = !sftp.WorkingDirectory.Equals("/") ? sftp.WorkingDirectory + newRemotePath : newRemotePath;
CreateDirectory(newRemotePath, false);
fileName = oldRemotePath.LastIndexOf('/') != -1 ? oldRemotePath.Substring(oldRemotePath.LastIndexOf('/') + 1) : oldRemotePath;
SftpFile file = sftp.ListDirectory(newRemotePath).SingleOrDefault(l => l.Name == fileName);
if (file!=null)
fileName = fileName.Substring(0, fileName.LastIndexOf(".")) + DateTime.Now.ToString("_yyyyMMddHHmmss") + "." + fileName.Substring(fileName.LastIndexOf(".") + 1);
sftp.RenameFile(oldRemotePath, newRemotePath + "/" + fileName);
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件移动失败,原因:{0}", ex.Message));
}
}
#endregion
#region 创建目录
/// <summary>
/// 创建目录
/// </summary>
/// <param name="remotePath">远程目录</param>
/// <param name="isDisconnect">是否关闭连接</param>
private void CreateDirectory(string remotePath,bool isDisconnect)
{
try
{
string[] paths = remotePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string curPath = "/";
for (int i = 0; i < paths.Length; i++)
{
curPath += paths[i];
if (!sftp.Exists(curPath))
{
sftp.CreateDirectory(curPath);
}
if (i < paths.Length - 1)
curPath += "/";
}
}
catch (Exception ex)
{
throw new Exception(string.Format("创建目录失败,原因:{0}", ex.Message));
}
}
#endregion
#region 获取目录列表
/// <summary>
/// 获取目录列表
/// </summary>
/// <param name="remotePath">远程目录路径</param>
/// <returns></returns>
public ArrayList GetDirectoryList(string remotePath)
{
try
{
var files = sftp.ListDirectory(remotePath);
var objList = new ArrayList();
foreach (var file in files)
{
if (!file.IsDirectory) continue;
if(!file.Name.Equals(".") && !file.Name.Equals(".."))
objList.Add(file.FullName);
}
return objList;
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP目录列表获取失败,原因:{0}", ex.Message));
}
}
#endregion
#region 删除远程目录
/// <summary>
/// 删除远程目录(包含目录内文件、子目录)
/// </summary>
/// <param name="remoteDirectory">远程目录</param>
public void DeleteDirectory(string remoteDirectory)
{
try
{
//delete files
var files = sftp.ListDirectory(remoteDirectory);
foreach (var file in files)
{
if (!file.IsDirectory)
sftp.DeleteFile(file.FullName);
else {
if(!file.Name.Equals(".") && !file.Name.Equals(".."))
{
DeleteDirectory(file.FullName);
}
}
}
sftp.DeleteDirectory(remoteDirectory);
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP目录删除失败,原因:{0}", ex.Message));
}
}
#endregion
#region 获取SFTP数据表格
/// <summary>
/// 获取SFTP数据表格
/// </summary>
/// <param name="remotePath">远程路径</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string remotePath)
{
StreamReader sr = null;
try
{
DataTable dt = new DataTable();
Connect();
sr = sftp.OpenText(remotePath);
//记录每次读取的一行记录
string strLine = "";
//记录每行记录中的各字段内容
string[] aryLine;
//标示列数
int columnCount = 0;
//标示是否是读取的第一行
bool IsFirst = true;
//逐行读取CSV中的数据
while ((strLine = sr.ReadLine()) != null)
{
aryLine = strLine.Trim().Split('\t'); //把读取到的内容分割
if (IsFirst == true)
{
IsFirst = false;
columnCount = aryLine.Length;
//创建列
for (int i = 0; i < columnCount; i++)
{
if (!dt.Columns.Contains(aryLine[i]))
{
DataColumn dc = new DataColumn(aryLine[i]);
dt.Columns.Add(dc);
}
else
columnCount--;
}
}
else
{
DataRow dr = dt.NewRow(); //创建行
for (int j = 0; j < dt.Columns.Count; j++)
{
dr[j] = aryLine.Length > j ? aryLine[j] : "";
}
dt.Rows.Add(dr);
}
}
return dt;
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件转换失败,原因:{0}", ex.Message));
}
finally
{
sr.Dispose();
sr.Close();
Disconnect();
}
}
#endregion
#region CSV => DataTable filetype
public DataTable GetDataTable(string remotePath, string filetype)
{
StreamReader sr = null;
try
{
DataTable dt = new DataTable();
sr = sftp.OpenText(remotePath);
//记录每次读取的一行记录
string strLine = "";
//记录每行记录中的各字段内容
string[] aryLine;
//标示列数
int columnCount = 0;
//标示是否是读取的第一行
bool IsFirst = true;
//逐行读取CSV中的数据
while ((strLine = sr.ReadLine()) != null)
{
aryLine = strLine.Trim().Split('\t'); //把读取到的内容分割
if (IsFirst == true)
{
IsFirst = false;
columnCount = aryLine.Length;
//创建列
for (int i = 0; i < columnCount; i++)
{
if (!dt.Columns.Contains(aryLine[i]))
{
string columnName = GetColumnName(aryLine[i], filetype);
DataColumn dc = new DataColumn(columnName);
dt.Columns.Add(dc);
}
else
columnCount--;
}
}
else
{
DataRow dr = dt.NewRow(); //创建行
for (int j = 0; j < dt.Columns.Count; j++)
{
//去除前导0
if (dt.Columns[j].ColumnName.Equals("KUNNR") || dt.Columns[j].ColumnName.Equals("MATNR") || dt.Columns[j].ColumnName.Equals("Invoice_Create_Date") || dt.Columns[j].ColumnName.Equals("Invoice_Create_Time") || dt.Columns[j].ColumnName.Equals("Invoice_Release_Date") || dt.Columns[j].ColumnName.Equals("Invoice_Release_Time"))
dr[j] = aryLine.Length > j ? aryLine[j].TrimStart('0') : "";
//decimal 类型转换
else if (dt.Columns[j].ColumnName.Equals("Grossweight") || dt.Columns[j].ColumnName.Equals("NetWeight") || dt.Columns[j].ColumnName.Equals("ProductListPrice"))
{
dr[j] = aryLine[j].ToDecimal();
}
//int 类型转换
else if (dt.Columns[j].ColumnName.Equals("Per") || dt.Columns[j].ColumnName.Equals("PlannedDeliveryTime") || dt.Columns[j].ColumnName.Equals("GRT"))
{
dr[j] = aryLine[j].ToInt();
}
else
dr[j] = aryLine.Length > j ? aryLine[j] : "";
if (aryLine.Length < columnCount && j == aryLine.Length - 1)
j = dt.Columns.Count;
}
dt.Rows.Add(dr);
}
}
return dt;
}
catch (Exception ex)
{
throw new Exception(string.Format("SFTP文件转换失败,原因:{0}", ex.Message));
}
finally
{
sr.Dispose();
sr.Close();
}
}
private string GetColumnName(string columnName, string filetype)
{
string restr = columnName;
switch (filetype)
{
case "SO_PO_DOWNLOAD":
switch (columnName)
{
case "SO Number":
restr = "VBELN";
break;
case "SO Cust. PO No.":
restr = "BSTKD";
break;
case "Customer PO line item No":
restr = "CustItemNo";
break;
case "ZBA3 DATE":
restr = "ZBA3_DATE";
break;
case "ZBAV DATE":
restr = "ZBAV_DATE";
break;
case "ZOP3 DATE":
restr = "ZOP3_DATE";
break;
case "Credit Block":
restr = "CMGST";
break;
case "Credit Block Description":
restr = "CMGST_TEXT";
break;
case "Delivery number":
restr = "DeliveryNumber";
break;
case "Delivery Created date":
restr = "LFDAT";
break;
case "Delivery quantity":
restr = "LFIMG";
break;
case "Vendor Name":
restr = "NAME1";
break;
case "Delivery item":
restr = "LIPS_POSNR";
break;
case "Material number":
restr = "MATNR";
break;
case "SO Net Value Item":
restr = "NETWR";
break;
case "SO Item":
restr = "POSNR";
break;
case "SO Item Category":
restr = "PSTYV";
break;
case "Billing number":
restr = "InvoiceNo";
break;
case "Billing Item":
restr = "InvoiceItemNo";
break;
case "MLFB":
restr = "YYBCEZNDR";
break;
case "Options":
restr = "Options";
break;
case "GR Quantity":
restr = "WEMNG";
break;
case "GR Date":
restr = "GR_date";
break;
case "EKES_EINDT_AB":
restr = "EINDT_AB";
break;
case "EKES_EINDT_LA":
restr = "EINDT_LA";
break;
case "PO item confirmed AB qty":
restr = "MENGE_AB";
break;
case "PO item confirmed LA qty":
restr = "MENGE_LA";
break;
case "PO Number":
restr = "EBELN";
break;
case "PO Item":
restr = "EBELP";
break;
case "Customer Number":
restr = "KUNNR";
break;
case "Customer Name1":
restr = "KNA1_NAME1";
break;
case "SO Date":
restr = "AUDAT";
break;
case "PO date":
restr = "BSTDK";
break;
case "Discount":
restr = "Discount";
break;
case "Cumulative Order Quantity in Sales":
restr = "ItemRequiredQuantity";
break;
case "Material Description":
restr = "ARKTX";
break;
case "ZOP2 DATE":
restr = "ZOP2_DATE";
break;
case "ZRDE DATE":
restr = "ZRDE_DATE";
break;
case "ZLAV DATE":
restr = "ZLAV_DATE";
break;
case "Employee ID":
restr = "Employee_ID";
break;
case "Employee Name":
restr = "Employee_Name";
break;
case "VBEZ":
restr = "VBEZ";
break;
case "POM-item":
restr = "POM_Item";
break;
case "ZMIN":
restr = "ZMIN_Block";
break;
case "DLBL":
restr = "Delivery_Block";
break;
case "Header status":
restr = "Order_Status";
break;
case "Reason for rejection":
restr = "Reason_For_Rejection";
break;
case "Invoice Qty":
restr = "Invoice_Qty";
break;
case "Invoice creation date":
restr = "Invoice_Create_Date";
break;
case "Invoice creation time":
restr = "Invoice_Create_Time";
break;
case "Invoice release date":
restr = "Invoice_Release_Date";
break;
case "Invoince release time":
restr = "Invoice_Release_Time";
break;
case "email address":
restr = "Email_Address";
break;
case "SO Time":
restr = "SO_Time";
break;
case "SPR No":
restr = "SPR_No";
break;
case "PGI Date":
restr = "PGI_Date";
break;
case "PGI Time":
restr = "PGI_Time";
break;
case "Customer required date":
restr = "Customer_Required_Date";
break;
case "VBEZ-CODE":
restr = "VBEZ_Code";
break;
default:
restr = columnName;
break;
}
break;
case "MATERIAL_STOCK_DOWNLOAD":
switch (columnName)
{
case "Base Unit":
restr = "Base_Unit";
break;
case "Material Number":
restr = "Material_Number";
break;
case "Plant":
restr = "Plant";
break;
case "Storage Location":
restr = "Storage_Location";
break;
case "Own and consignment stock":
restr = "Unrestricted_Stock";
break;
default:
restr = columnName;
break;
}
break;
case "MATERIAL_MASTER_DOWNLOAD":
switch (columnName)
{
case "Base Unit":
restr = "BaseUnit";
break;
case "Currency":
restr = "Currency";
break;
case "Dist Channel":
restr = "DistChannel";
break;
case "Gross weight":
restr = "Grossweight";
break;
case "GRT":
restr = "GRT";
break;
case "Item Category Group":
restr = "ItemCategoryGroup";
break;
case "Material Description":
restr = "MaterialDescription";
break;
case "Material Group":
restr = "MaterialGroup";
break;
case "Material Number":
restr = "MaterialNumber";
break;
case "Print":
restr = "MLFB";
break;
case "Sort":
restr = "MLFB_Sort";
break;
case "Net Weight":
restr = "NetWeight";
break;
case "Options":
restr = "Options";
break;
case "Per":
restr = "Per";
break;
case "Planned Delivery Time":
restr = "PlannedDeliveryTime";
break;
case "Plant":
restr = "Plant";
break;
case "Product List Price":
restr = "ProductListPrice";
break;
case "Profit Center":
restr = "ProfitCenter";
break;
case "Sales Org":
restr = "SalesOrg";
break;
case "Unit of Measure":
restr = "UnitofMeasure";
break;
case "Vendor Name":
restr = "VendorName";
break;
case "Vendor Number":
restr = "VendorNumber";
break;
case "Weight UOM":
restr = "WeightUOM";
break;
case "Min. dely qty"://Min.order qty
restr = "Min_order_qty";
break;
case "Material Status":
restr = "MaterialStatus";
break;
case "GBK":
restr = "GBK";
break;
case "Product hierarchy":
restr = "ProductHierarchy";
break;
default:
restr = columnName;
break;
}
break;
}
return restr;
}
#endregion
#region CSV => DataTable by filetype new
/// <summary>
/// CSV 提取数据到 DataTable
/// </summary>
/// <param name="remotePath">远程路径</param>
/// <param name="filetype">文件类别(订单/库存/物料)</param>
/// <returns></returns>
public DataTable GetDataTable_New(string remotePath, string filetype)
{
using (StreamReader sr = sftp.OpenText(remotePath))
{
DataTable dt = new DataTable();
//记录每次读取的一行记录
string strLine = "";
//记录每行记录中的各字段内容
string[] aryLine;
//标示是否是读取的第一行
bool IsFirst = true;
//逐行读取CSV中的数据
while ((strLine = sr.ReadLine()) != null)
{
aryLine = strLine.Trim().Split('\t'); //把读取到的内容分割
if (IsFirst == true)
{
//创建列
IsFirst = false;
for (int i = 0; i < aryLine.Length; i++)
{
string columnName = GetColumnName_New(aryLine[i], filetype);
if (!dt.Columns.Contains(columnName))
dt.Columns.Add(new DataColumn(columnName));
}
}
else
{
//创建行
DataRow dr = dt.NewRow();
for (int j = 0; j < dt.Columns.Count; j++)
dr[j] = aryLine.Length > j && !string.IsNullOrEmpty(aryLine[j]) ? aryLine[j] : "";
dt.Rows.Add(dr);
}
}
return dt;
}
}
/// <summary>
/// 映射字段名
/// </summary>
/// <param name="columnName">DT 列名</param>
/// <param name="filetype">文件类别</param>
/// <returns></returns>
private string GetColumnName_New(string columnName, string filetype)
{
string order = System.Configuration.ConfigurationManager.AppSettings["Order"];
string stock = System.Configuration.ConfigurationManager.AppSettings["Stock"];
string master = System.Configuration.ConfigurationManager.AppSettings["Master"];
string restr = columnName;
if (filetype.Equals(order))
{
switch (columnName)
{
//未完成
default:
restr = columnName;
break;
}
}
if (filetype.Equals(stock))
{
switch (columnName)
{
case "Material Number":
restr = "MaterialNumber";
break;
case "Own and consignment stock":
restr = "StockQuantity";
break;
default:
restr = columnName;
break;
}
}
if (filetype.Equals(master))
{
switch (columnName)
{
case "Material Number":
restr = "MaterialNumber";
break;
case "Print":
restr = "MLFB_Print";
break;
case "Sort":
restr = "MLFB_Sort";
break;
case "Material Description":
restr = "MaterialDescription";
break;
case "Material Group":
restr = "MaterialGroup";
break;
case "Item Category Group":
restr = "ItemCategoryGroup";
break;
case "Base Unit":
restr = "BaseUnit";
break;
case "Currency":
restr = "Currency";
break;
case "Dist Channel":
restr = "DistChannel";
break;
case "Gross weight":
restr = "GrossWeight";
break;
case "Net Weight":
restr = "NetWeight";
break;
case "GRT":
restr = "GRT";
break;
case "Options":
restr = "Options";
break;
case "Per":
restr = "Per";
break;
case "Planned Delivery Time":
restr = "PlannedDeliveryTime";
break;
case "Plant":
restr = "Plant";
break;
case "Product List Price":
restr = "ListPrice";
break;
case "Profit Center":
restr = "ProfitCenter";
break;
case "Sales Org":
restr = "SalesOrg";
break;
case "Unit of Measure":
restr = "UnitOfMeasure";
break;
case "Weight UOM":
restr = "WeightUOM";
break;
case "Vendor Name":
restr = "VendorName";
break;
case "Vendor Number":
restr = "VendorNumber";
break;
case "Min. dely qty":
restr = "Min_Dely_Qty";
break;
case "Material Status":
restr = "MaterialStatus";
break;
case "GBK":
restr = "GBK";
break;
case "Product hierarchy":
restr = "ProductHierarchy";
break;
default:
restr = columnName;
break;
}
}
return restr;
}
#endregion
}
FileUpload 上传文件,并实现c#使用Renci.SshNet.dll实现SFTP文件传输的更多相关文章
- Webform之FileUpload(上传按钮控件)简单介绍及下载、上传文件时图片预览
1.FileUpload上传控件:(原文:http://www.cnblogs.com/hide0511/archive/2006/09/24/513201.html) FileUpload 控件显示 ...
- .NET FileUpLoad上传文件
一.上传扫描件到服务器,自定义创建文件夹(如果存在该文件夹,则无需创建),并判断格式以及文件大小进行保存: 首先创建一个保存按钮事件: protected void btnSave_Click(obj ...
- Java Web文件上传原理分析(不借助开源fileupload上传jar包)
Java Web文件上传原理分析(不借助开源fileupload上传jar包) 博客分类: Java Web 最近在面试IBM时,面试官突然问到:如果让你自己实现一个文件上传,你的代码要如何写,不 ...
- [.ashx檔?泛型处理例程?]基础入门#2....FileUpload上传前,预览图片(两种作法--ashx与JavaScript)
原文出處 http://www.dotblogs.com.tw/mis2000lab/archive/2013/08/20/ashx_beginner_02_fileupload_picture_p ...
- spring mvc 图片上传,图片压缩、跨域解决、 按天生成文件夹 ,删除,限制为图片代码等相关配置
spring mvc 图片上传,跨域解决 按天生成文件夹 ,删除,限制为图片代码,等相关配置 fs.root=data/ #fs.root=/home/dev/fs/ #fs.root=D:/fs/ ...
- ASP.NET使用FileUpload上传文件
前台代码: <asp:FileUpload ID="fuKeleyi" runat="server" /> <asp:Button ID=&q ...
- 解决COS、FileUpload上传文件时中文文件名乱码问题
方法: MultipartParser mp = new MultipartParser(request, 10*1024*1024); mp.setEncoding("GBK") ...
- SpringMVC使用FileUpload上传文件
进口FileUpload和common-io的Jar包 注意:1.Struts2其它方法需要使用的:struts2过滤,将改变reqeust类型,由HttpServletRequest成为MultiP ...
- JSP/Serlet 使用fileupload上传文件
需要引用的jar commons-fileupload-1.3.1.jar commons-io-2.2.jar index.jsp <body> <center> <h ...
随机推荐
- IOS懒加载
1.懒加载基本 懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小).所谓懒加载,写的是其get方法. 注意:如果是懒加载的话则一定要注意先判断是否已经有了,如果没有那么再去进行实例化 ...
- jquery 插件
1 jquery.slimscroll.min.js:虚拟滚轴 2 jquery.steps.js:步骤(注册下一步) 3 jquery-barcode.js:条形码
- 前端学习 第四弹: HTML(一)
前端学习 第四弹: HTML(一) 元素分类:块元素 内联元素 块级元素在浏览器显示时,通常会以新行来开始(和结束). 例子:<h1>, <p>, <ul>, &l ...
- 【jq】c#零基础学习之路(1)Hello World!
从今天起我会持续发表,这个就是一个日记型的,学习编程是枯燥的,况且我们还是零基础. 学前准备 1.编译环境 vs2010.vs2012.vs2015...(本人用的是vs2010旗舰版).vs2010 ...
- 高级Linux SA需要会做的事情
高级Linux SA需要会做的事情:linux---------系统安装(光盘或自动化安装)linux---------系统常用工具安装(sudo,ntp,yum,rsync,lrzsz syssta ...
- 命名空间System.Threading命名空间的同步锁 Monitor类
官方备注: Monitor类通过向单个线程授予对象所来控制对对象的访问.对象所提供限制访问代码块的能力.当一个线程拥有对象的锁时,其他任何线程都不能获取该锁.还可以使用Monitor来确保不会允许其他 ...
- python使用xlrd模块读写excel
1.行列索引均从0开始2.int数据被读成float数据,解决办法,if type(value) == float and value%1 == 0,value= int(value)模块读 #!/u ...
- java获得某个月的天数
/*** 方法一*/ String strDate = "2012-02"; SimpleDateFormat format = new SimpleDateFormat(&quo ...
- EntityFrameWork使用
1.简单查询: SQL: ? 1 SELECT * FROM [Clients] WHERE Type=1 AND Deleted=0 ORDER BY ID EF: ? 1 2 3 4 5 6 7 ...
- ubuntu中常用软件的安装
1.有道词典 1.百度有道词典,进入有道首页,点"下载词典客户端",下载对应版本. 2.打开终端,进入下载目录,输入sudo dpkg -i youdao-dict_1.0.2~u ...