本文整理汇总了C#中System.Web.UI.WebControls.FileUpload类的典型用法代码示例。如果您正苦于以下问题:C# FileUpload类的具体用法?C# FileUpload怎么用?C# FileUpload使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUpload类属于System.Web.UI.WebControls命名空间,在下文中一共展示了FileUpload类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: fileUploadName
protected String fileUploadName(FileUpload fileupload)
{
try
{
string fileUploadDir = Server.MapPath(General.EMP_ARTICLE_LOGO + txt_Title.Text.Trim() + "/");
if (!System.IO.Directory.Exists(fileUploadDir))
{
System.IO.Directory.CreateDirectory(fileUploadDir);
}
System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream(fileupload.PostedFile.InputStream);
int imageHeight = imageToBeResized.Height;
int imageWidth = imageToBeResized.Width;
int maxHeight = 196;
int maxWidth = 300;
imageHeight = (imageHeight * maxWidth) / imageWidth;
imageWidth = maxWidth;
if (imageHeight > maxHeight)
{
imageWidth = (imageWidth * maxHeight) / imageHeight;
imageHeight = maxHeight;
}
Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
bitmap.Save(fileUploadDir + fileupload.FileName);
return fileupload.PostedFile.FileName.ToString();
}
catch (Exception)
{
return "";
}
}
示例2: UploadFile
public static string UploadFile(FileUpload fileUpload)
{
if (fileUpload == null)
{
return string.Empty;
}
var tempMediaPath = ConfigurationHelper.GetScrudParameter("TempMediaPath");
var uploadDirectory = HttpContext.Current.Server.MapPath(tempMediaPath);
if (!Directory.Exists(uploadDirectory))
{
Directory.CreateDirectory(uploadDirectory);
}
var id = Guid.NewGuid().ToString();
if (fileUpload.HasFile)
{
id += Path.GetExtension(fileUpload.FileName);
id = Path.Combine(uploadDirectory, id);
fileUpload.SaveAs(id);
}
return id;
}
示例3: GetSavedFile
public static string GetSavedFile(FileUpload fUploader, bool autoGenerateName)
{
string guid = string.Empty;
if (fUploader.PostedFile != null)
{
try
{
if (!fUploader.PostedFile.FileName.Contains('.'))
return guid;
string[] fileext = fUploader.PostedFile.FileName.Split('.');
if (autoGenerateName)
{
guid = Guid.NewGuid().ToString();
guid += "." + fileext[fileext.Length - 1].ToString();
}
else
guid = fUploader.PostedFile.FileName;
SaveJPGWithCompressionSetting(fUploader.FileContent, ExpressoConfig.GeneralConfigElement.GetPhysicalUploadPath + guid);
}
catch (Exception ex)
{
throw ex;
}
}
return guid;
}
示例4: CheckContainImage
public static bool CheckContainImage(FileUpload ful)
{
//TODO: Kiem tra anh xem ng dùng có chọn ko?
if (ful.HasFile)
return true;
else return false;
}
示例5: img
public string img(FileUpload upload)
{
string str = "";
string filename = upload.FileName;
if (filename.Equals(""))
{
MessShowBox.show("图片不能为空", this);
}
else
{
string type = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
if (type == "jpg" || type == "bmp" || type == "gif" || type == "png")
{
str = "/public/user_img/" + DateTime.Now.ToString("yyyyMMddhhmmss") + filename;
if (!File.Exists(filename))
{
upload.SaveAs(MapPath(str));
}
else
{
MessShowBox.show("文件已存在,请重命名后再上传", this);
}
}
else
{
MessShowBox.show("上传的图片个是不正确,图片格式必须是|jpg|bmp|gif|png", this);
}
}
return str;
}
示例6: UploadBinary
public UploadBinary()
{
InnerControlID = "FileUploader";
_fileUploadControl = new FileUpload { ID = InnerControlID };
_info = new Label { ID = "FileUploaderInfo" };
}
示例7: btnpdfUpload_Click
protected void btnpdfUpload_Click(object sender, EventArgs e)
{
try
{
FileUpload FilePP = new FileUpload();
FilePP = pdfFileUpload;
if (FilePP.HasFile)
{
string getExtention = Path.GetExtension(FilePP.FileName);
//path = path + @"\" + PPImg;
//FilePP.PostedFile.SaveAs(path);
if (getExtention == ".pdf" || getExtention == ".PDF")
{
// hidFileName.Value = filename;
// string path = HttpContext.Current.Server.MapPath(WebConfigurationManager.AppSettings["AttachmentPath"] + "/ModuleContents/");
string loc = "/download/";
string path = HttpContext.Current.Server.MapPath(loc);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + "fxpresent" + getExtention;
FilePP.PostedFile.SaveAs(path);
string message = "Message is <span class='actionTopic'>Your File Uploaded successfully.</span> Successfully.";
MyAlertBox("var callbackOk = function () { window.location = \"\"; }; SuccessAlert(\"" +
"Process Succeed" + "\", \"" + message + "\", \"\");");
}
else
{
string message = "Message is <span class='actionTopic'>Your File extension does not match.</span> Successfully.";
MyAlertBox("var callbackOk = function () { window.location = \"\"; }; WarningAlert(\"" +
"Process Succeed" + "\", \"" + message + "\", \"\");");
}
}
else
{
string message = " <span class='actionTopic'>" + "Sorry Please Select Your File." + "</span>.";
MyAlertBox("var callbackOk = function () { window.location = \"\"; }; WarningAlert(\"" + "Warning!!" + "\", \"" + message + "\",\"\");");
}
}
catch (Exception ex)
{
string message = ex.Message;
if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
}
}
示例8: AddControl
private static HtmlTableCell AddControl(JobControl_Get_Result control)
{
HtmlTableCell cell = new HtmlTableCell();
Control c = new Control();
switch (control.ControlTypeName)
{
case "TextBox":
c = new TextBox();
c.ID = control.JobControlID + control.ControlTypeName + control.ControlName;
break;
case "CheckBox":
c = new CheckBox();
c.ID = control.JobControlID + control.ControlTypeName + control.ControlName;
break;
case "ImageUpload":
c = new FileUpload();
c.ID = control.JobControlID + control.ControlTypeName + control.ControlName;
break;
}
cell.Controls.Add(c);
return cell;
}
示例9: fileupload
public string fileupload(string name, int id)
{
string fileth = "";
string str = "";
string fid = name;
if (File(name))
{
if (PdMusic(fid))
{
fid = name.Substring(0, name.LastIndexOf('.')) + "_IMG" + DateTime.Now.ToString("yyyyHHmmssfff") + Path.GetExtension(name);
}
fileth = "~/upload/images/" + fid;
FileInfo filee = new FileInfo(Server.MapPath(fileth));//删除以前的老文件
if (filee.Exists)
{
filee.Delete();
}
FileUpload FiLe = new FileUpload();
FiLe.SaveAs(Server.MapPath(fileth));
//判断是修改状态,还是添加状态
if (id == 0)//添加
{
}
else
{//修改
Daxu.Entity.newlist newlistInfo = new Daxu.Entity.newlist();
newlistInfo.cnen = fid;
Daxu.BLL.newlistBll.UpdateInewlist(newlistInfo);
}
str = fid;
}
return str;
// return "你好!";
}
示例10: Create
public ActionResult Create(HttpPostedFileBase file)
{
//foreach (string file in Request.Files)
//{
// HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
// if (hpf.ContentLength == 0)
// continue;
// string savedFileName = Path.Combine(
// AppDomain.CurrentDomain.BaseDirectory,
// Path.GetFileName(hpf.FileName));
// hpf.SaveAs(savedFileName);
//}
Flyer flyer = new Flyer();
if (TryUpdateModel(flyer))
{
//UPLOAD THE FLYER
FileUpload uploader = new FileUpload();
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/resources/flyers"), fileName);
file.SaveAs(path);
flyer.Location = path;
_flyerRepository.Create(flyer);
//TODO create flyer
//flyers.CreateFlyer(flyer);
return RedirectToAction("Index");
}
return View();
}
示例11: UploadBrandLogo
private string UploadBrandLogo(int BrandID,FileUpload fu)
{
string ImageUrl, ImageShortUrl, Message;
CommonImageUpload.Upload(fu, out ImageUrl, out ImageShortUrl, out Message);
return ImageShortUrl;
}
示例12: GetFileUpload
private static FileUpload GetFileUpload(string id)
{
FileUpload fileUpload = new FileUpload();
fileUpload.ID = id;
return fileUpload;
}
示例13: FileSc
/// <summary>
/// 上传文件
/// </summary>
/// <param name="PosPhotoUpload">控件</param>
/// <param name="saveFileName">保存的文件名</param>
/// <param name="imagePath">保存的文件路径</param>
public string FileSc(FileUpload PosPhotoUpload, string saveFileName, string imagePath)
{
string state = "";
if (PosPhotoUpload.HasFile)
{
if (PosPhotoUpload.PostedFile.ContentLength / 1024 < 10240)
{
string MimeType = PosPhotoUpload.PostedFile.ContentType;
if (String.Equals(MimeType, "image/gif") || String.Equals(MimeType, "image/pjpeg"))
{
string extFileString = System.IO.Path.GetExtension(PosPhotoUpload.PostedFile.FileName);
PosPhotoUpload.PostedFile.SaveAs(HttpContext.Current.Server.MapPath(imagePath));
}
else
{
state = "上传文件类型不正确";
}
}
else
{
state = "上传文件不能大于10M";
}
}
else
{
state = "没有上传文件";
}
return state;
}
示例14: AlbumImageUpLoad
public enum enumState{ noFile,fileEx,fileSuccess,fileFailed};//0没选中文件;1扩展名出错;2成功;3失败;
//图片上传
public enumState AlbumImageUpLoad(FileUpload fileUpload, string urlPath, string filename)
{
if (fileUpload.PostedFile.FileName == "")
{
return enumState.noFile;
}
else
{
string filepath = fileUpload.PostedFile.FileName;
string fileEx = filepath.Substring(filepath.LastIndexOf(".") + 1);//string filename = lbRandomCode.Text + ".";
string serverpath = urlPath + filename + "." + fileEx; //string serverpath = Server.MapPath("~/Images/Album/") + filename + fileEx;
if (fileEx == "jpg" || fileEx == "bmp" || fileEx == "gif" || fileEx == "JPG" || fileEx == "BMP" || fileEx == "GIF")
{
fileUpload.PostedFile.SaveAs(serverpath);
//imgAlbumCover.ImageUrl = "~/Images/Album/" + filename + fileEx;
//lbImageUrl.Text = "~/Images/Album/" + filename + fileEx;
//imgAlbumCover.ImageUrl = lbImageUrl.Text;
return enumState.fileSuccess;
}
else
{
return enumState.fileEx;
}
}
}
示例15: Upload
public string Upload(FileUpload fileUpload, string ftpServerIP, string ftpUserID, string ftpPassword)
{
string filename = fileUpload.FileName;
string sRet = "上传成功!";
FileInfo fileInf = new FileInfo(fileUpload.PostedFile.FileName);
string uri = "ftp://" + ftpServerIP + "/" + filename;
FtpWebRequest reqFTP = (FtpWebRequest)WebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = "STOR";
reqFTP.UseBinary = true;
reqFTP.UsePassive = false;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
FileStream fs = fileInf.OpenRead();
try
{
Stream strm = reqFTP.GetRequestStream();
for (int contentLen = fs.Read(buff, 0, buffLength); contentLen != 0; contentLen = fs.Read(buff, 0, buffLength))
{
strm.Write(buff, 0, contentLen);
}
strm.Close();
fs.Close();
}
catch (Exception ex)
{
sRet = ex.Message;
}
return sRet;
}