本文整理汇总了C#中FileUpload.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# FileUpload.SaveAs方法的具体用法?C# FileUpload.SaveAs怎么用?C# FileUpload.SaveAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUpload
的用法示例。
在下文中一共展示了FileUpload.SaveAs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload
private void Upload(FileUpload fu, string name)
{
if (fu.HasFile)
{
try
{
string filename = System.IO.Path.GetFileName(fu.FileName);
string fileUpload = Server.MapPath(@"~/Data/Images/") + filename;
if (System.IO.File.Exists(fileUpload))
System.IO.File.Delete(fileUpload);
fu.SaveAs(fileUpload);
System.Drawing.Image image1 = System.Drawing.Image.FromFile(fileUpload);
string fileAceess = Server.MapPath(@"~/Data/Images/" + name + ".jpg");
if (System.IO.File.Exists(fileAceess))
System.IO.File.Delete(fileAceess);
image1.Save(fileAceess, System.Drawing.Imaging.ImageFormat.Jpeg);
if (System.IO.File.Exists(fileUpload))
System.IO.File.Delete(fileUpload);
}
catch (Exception ex)
{
}
}
}
示例2: UpdateDocumentDetails
public void UpdateDocumentDetails()
{
string DocName = default(System.String);
int DocStatus = default(System.Int32);
int OppsID = default(System.Int32);
System.DateTime LastModifyDate = default(System.DateTime);
//For LastModifyDate
{
TextBox LastModifyDateCal = new TextBox();
LastModifyDateCal = (TextBox)DocumentDW.FindControl("LastModifyDate");
if ((LastModifyDateCal != null))
{
if (!string.IsNullOrEmpty(LastModifyDateCal.Text))
{
LastModifyDate = Convert.ToDateTime(LastModifyDateCal.Text.Trim());
}
}
}
//For Document Status
DropDownList DocStatusDDList = new DropDownList();
DocStatusDDList = (DropDownList)DocumentDW.FindControl("ddlDocStatus");
if ((DocStatusDDList != null))
{
DocStatus = Convert.ToInt32(DocStatusDDList.SelectedValue);
}
//For Opportunity
DropDownList OpportunityDDList = new DropDownList();
OpportunityDDList = (DropDownList)DocumentDW.FindControl("ddlOpportunity");
if ((OpportunityDDList != null))
{
OppsID = Convert.ToInt32(OpportunityDDList.SelectedValue);
}
FileUpload FileUploadControl = new FileUpload();
FileUploadControl = (FileUpload)DocumentDW.FindControl("Upload");
if ((FileUploadControl != null))
{
//Add GUID
DocName = System.Guid.NewGuid() + "_" + FileUploadControl.FileName.ToString();
if (string.IsNullOrEmpty(DocName))
{
//User has not uploaded new file so keep the same filename
DocName = hidDocumentName.Value;
}
else
{
//Save the actual file in the documents folder
//FileUploadControl.SaveAs(Server.MapPath(DocName));
//FileUploadControl.SaveAs(ConfigurationManager.AppSettings["DocumentsUploadLocation"] + DocName);
FileUploadControl.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["DocumentsUploadLocation"] + DocName));
}
}
//Now Update
new SandlerRepositories.DocumentsRepository().Update(Convert.ToInt32(hidDocumentID.Value), OppsID, DocName, DocStatus, LastModifyDate,CurrentUser);
}
示例3: dvDocument_ItemInserting
protected void dvDocument_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
string DocName = default(System.String);
int DocStatus = default(System.Int32);
System.DateTime LastModifyDate = default(System.DateTime);
//for file
FileUpload FileUploadControl = new FileUpload();
FileUploadControl = (FileUpload)dvDocument.FindControl("Upload");
if ((FileUploadControl != null))
{
//Create GUID and modify Document Name - This will ensure that document will be unique for all users even if they use same name
DocName = System.Guid.NewGuid() + "_" + FileUploadControl.FileName.ToString();
//check if we have Document name
if (!string.IsNullOrEmpty(DocName))
{
//Save the actual file in the documents folder- DocumentsUploadLocation
//FileUploadControl.SaveAs(Server.MapPath(DocName);
FileUploadControl.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["DocumentsUploadLocation"] + DocName));
}
else
{
//There is not file to attach so inform the user
ClientScript.RegisterStartupScript(this.GetType(), "NoDocument", ("<script> alert('Please click on Browse button and select document to attach.'); </script>"));
e.Cancel = true;
}
}
//For LastModifyDate
{
TextBox LastModifyDateCal = new TextBox();
LastModifyDateCal = (TextBox)dvDocument.FindControl("LastModifyDate");
if ((LastModifyDateCal != null))
{
if (!string.IsNullOrEmpty(LastModifyDateCal.Text))
{
LastModifyDate = Convert.ToDateTime(LastModifyDateCal.Text.Trim());
}
}
}
//For Document Status
DropDownList DocStatusDDList = new DropDownList();
DocStatusDDList = (DropDownList)dvDocument.FindControl("ddlDocStatus");
if ((DocStatusDDList != null))
{
DocStatus = Convert.ToInt32(DocStatusDDList.SelectedValue);
}
if (!e.Cancel)
{
new SandlerRepositories.DocumentsRepository().Insert(Convert.ToInt32(ddlOpportunity.SelectedValue), Convert.ToInt32(ddlCompany.SelectedValue), DocStatus, DocName, LastModifyDate,CurrentUser);
lblResult.Text = "Document attached Successfully!";
}
}
示例4: UploadImage
public void UploadImage(FileUpload fileupload, string fileName)
{
try
{
string path = "~/images/products/" + fileName;
fileupload.SaveAs(Server.MapPath(path));
}
catch (Exception)
{
}
}
示例5: UploadImage
public string UploadImage(FileUpload fileupload, string fill)
{
try
{
string path = "~/images/products/" + DateTime.Now.ToString("yyyyMMddhhmmss") + fill + "." + fileupload.FileName;
fileupload.SaveAs(Server.MapPath(path));
return path;
}
catch (Exception)
{
return "";
}
}
示例6: Addphoto
public string Addphoto(FileUpload Photo)
{
if ((Photo.FileName) != "")
{
string ext = Path.GetExtension(Photo.FileName);
int index = Photo.FileName.IndexOf('.');
string filename = Photo.FileName.Substring(0, index) + Session.SessionID + ext;
string path = Server.MapPath("~/Profile_Photo/" + filename + "");
Photo.SaveAs(path);
return filename;
}
else
return null;
}
示例7: GetSavedFileName
private string GetSavedFileName(FileUpload f1)
{
string medical_id = DateTime.Now.ToString("yyyyMMddHmms");
string doc_code = "0000";
string immagefille = "";
string imagefile = null;
string ext = System.IO.Path.GetExtension(f1.PostedFile.FileName);
if (f1.HasFile)
{
Hashtable fed = new Hashtable();
fed.Add("0000", "0000");
if (fed.Contains(doc_code))
{
if ((ext.ToUpper() == ".JPG") || (ext.ToUpper() == ".PNG"))
{
imagefile = medical_id + "_" + doc_code;
//file.SaveAs(Page.MapPath("~/DOCUMENT_REPO/" + imagefile + ".jpg"));
f1.SaveAs(Page.MapPath("/MemberPics/" + imagefile + ext));
string file = Page.MapPath("/MemberPics/" + imagefile + ext);
immagefille = imagefile + ext;
// Util.ResizeMemberImage(file, file, 0, 0, true);
return immagefille;
}
else
{
//msgBox1.alert("Please Passport can not be in other format than .jpg");
return string.Empty;
}
}
}
else
{
imagefile = "no_image.jpg";
return imagefile;
}
return string.Empty;
}
示例8: UploadPhoto
public bool UploadPhoto(FileUpload fuPhoto, string pathShort, string photoName, int maxSizeKB, int intWidth, int intHeight, string strWatermark, int fontSize, out string errorMessage, out string fileName)
{
#region Remark
/*############################ Example ############################
Upload ไฟล์ พร้อมลดขนาดรูป
string outError;
string outFilename;
if (!clsIO.UploadPhoto(fuPhoto, "/Upload/PhotoBook/", "Book_" + "id", 512, 150, 0, "", 0, out outError, out outFilename))
{
lblSQL.Text = outError;
}
else
{
//ทำอะไรต่อ ถ้าอัพผ่าน
}
#################################################################*/
#endregion
bool rtnValue = true;
errorMessage = "";
fileName = "";
if (fuPhoto.HasFile == true)
{
if (FileTypeChecker(fuPhoto.FileName) != "IMG")
{
errorMessage = "โปรดเลือกเฉพาะไฟล์รูปภาพ";
fuPhoto.Focus();
return false;
}
if (maxSizeKB > 0)
{
if (fuPhoto.PostedFile.ContentLength > maxSizeKB * 1000)
{
errorMessage = "ขนาดไฟล์ใหญ่เกิน " + maxSizeKB + " KB";
fuPhoto.Focus();
return false;
}
}
fileName = photoName + System.IO.Path.GetExtension(fuPhoto.FileName).ToLower();
FileExist(pathShort + fileName, true);
try
{
fuPhoto.SaveAs(System.Web.HttpContext.Current.Server.MapPath(pathShort + fileName));
}
catch (Exception ex)
{
errorMessage = "เกิดข้อผิดพลาด ขณะอัพโหลดไฟล์ไว้ที่ " + System.Web.HttpContext.Current.Server.MapPath(pathShort + fileName);
fuPhoto.Focus();
return false;
}
if (!ImageResize(intWidth, intHeight, pathShort + fileName, "", strWatermark, fontSize))
{
errorMessage = "เกิดข้อผิดพลาด ขณะย่อขนาดภาพ";
fuPhoto.Focus();
return false;
}
}
else
{
errorMessage = "ไม่พบไฟล์ที่ต้องการอัพโหลด";
fuPhoto.Focus();
return false;
}
return rtnValue;
}
示例9: UploadRefundDoc
private void UploadRefundDoc(FileUpload f1, string doc_code)
{
string file ="";
if (f1.HasFile)
{
bool checkDoc = CheckDocRequired(f1, validFileTypes);
bool checksize = CheckForSize(f1);
if (checkDoc == true && checksize == true)
{
string imagefile = null;
imagefile = f1.PostedFile.FileName;
string ext = System.IO.Path.GetExtension(f1.PostedFile.FileName);
if (f1.HasFile)
{
string snow = DateTime.Now.ToString("ddMMyyyyHms");
f1.SaveAs(Page.MapPath("/resume/" + snow + "." + ext));
file = Page.MapPath("/resume/" + snow + "." + ext);
CVUploadEx cp = new CVUploadEx();
cp.AdditionalInfo = additionaltxt.Text; ;
cp.cvFile = Util.BaseSiteUrl + "resume/" + snow + "." + ext;
cp.Id = 0;
cp.Email = emailtxt.Text;
cp.FullName = fullname.Text;
cp.PhoneNo = phonetxt.Text;
int result = DataService.Provider.SaveCVUploadEx(cp);
}
else
{
imagefile = "no_image.jpg";
}
}
else if (checkDoc == false && checksize == true)
{
msgBox1.alert("Kindly select an image in .jpg or .png Format, The selected file is invalid!");
return;
}
else if (checkDoc == false && checksize == false)
{
msgBox1.alert("Bad Format and Size, Please select a Valid File!");
return;
}
else if (checkDoc == true && checksize == false)
{
msgBox1.alert("File Limit Exceeded!");
return;
}
else { return; }
}
}
示例10: uploadFile
private string uploadFile(FileUpload fu, string strEx)
{
if (fu.HasFile)
{
string fileEx = fu.FileName.Substring(fu.FileName.LastIndexOf('.')).Remove(0, 1);
string[] arrEx = strEx.Split('|');
bool valid = false;
foreach (string ex in arrEx)
{
if (ex.Equals(fileEx, StringComparison.OrdinalIgnoreCase))
valid = true;
}
if (valid)
{
fu.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["UploadPath"] + "\\"+ Server.HtmlEncode(fu.FileName)));
return fu.FileName;
}
else
return null;
}
else
return null;
}
示例11: importExcel
/// <summary>
/// import from excel file to DataTable.
/// </summary>
/// <param name="fileUpload">FileUpload control upload excel file.</param>
/// <param name="sheetIndex">sheet page index</param>
/// <returns>DataTable</returns>
public DataTable importExcel(FileUpload fileUpload, int sheetIndex)
{
DataTable sheetInfo = null;
if (isExcel(fileUpload))
{
// upload file
string serverFolderPath = HttpContext.Current.Request.PhysicalApplicationPath + "upload\\";
string serverFileName = fileUpload.FileName.Insert(fileUpload.FileName.LastIndexOf('.'),
DateTime.Now.Ticks.ToString());
string filePath = serverFolderPath + serverFileName;
fileUpload.SaveAs(filePath);
// get sheet pages
string[] sheetNameArr = getExcelSheetNames(filePath);
if (sheetNameArr != null && sheetIndex <= sheetNameArr.Length - 1)
{
sheetInfo = GetAllDataInfo(filePath, sheetNameArr[sheetIndex]);
File.Delete(filePath);
}
}
return sheetInfo;
}
示例12: UploadRefundDoc
private string UploadRefundDoc(FileUpload f1)
{
bool checkDoc = false;
if (f1.HasFile)
{
checkDoc = CheckDocRequired(f1, validFileTypes);
}
bool checksize = CheckForSize(f1);
if (checkDoc == true && checksize == true)
{
string imagefile = System.DateTime.Now.ToString("ddMMyyyyHHmmss");
string ext = System.IO.Path.GetExtension(f1.PostedFile.FileName);
if (f1.HasFile)
{
if ((ext.ToLower() == ".jpg") || (ext.ToLower() == ".png"))
{
f1.SaveAs(Server.MapPath("/images/Toyota/banner-images/" + imagefile + ext));
string file = Server.MapPath("/images/Toyota/banner-images/" + imagefile + ext);
Util.ResizeImage(file, file, 859, 320, true);
return "/images/Toyota/banner-images/" + imagefile + ext;
}
else
{
msgBox1.alert("Please banner Image can not be in other format than .jpg or .png");
return string.Empty;
}
}
else
{
imagefile = "no_image.jpg";
return string.Empty;
}
}
else if (checkDoc == false && checksize == true)
{
msgBox1.alert("Kindly select saved Passport Photograph in .jpg Format, The selected file is invalid!");
return string.Empty;
}
else if (checkDoc == false && checksize == false)
{
msgBox1.alert("Bad Format and Size, Please select a Valid File!"); return string.Empty;
}
else if (checkDoc == true && checksize == false) { msgBox1.alert("File Limit Exceeded!"); return string.Empty; }
else { return string.Empty; }
}
示例13: ImageUpload
private string ImageUpload(FileUpload fluImage, Image imgEdit, string SaveImgPath)
{
string strFileName = string.Empty;
if (fluImage.HasFile)
{
SaveImgPath = Server.MapPath(SaveImgPath);
if (!Directory.Exists(SaveImgPath))
Directory.CreateDirectory(SaveImgPath);
string UploadedImage = fluImage.PostedFile.FileName;
FileInfo objFin = new FileInfo(UploadedImage);
string FileExtension = objFin.Extension;//UploadedImage.Remove(UploadedImage.LastIndexOf("."));
string VertualUrl0 = SaveImgPath + "\\Large";
//VertualUrl0 = Server.MapPath(VertualUrl0);
if (!Directory.Exists(VertualUrl0))
Directory.CreateDirectory(VertualUrl0);
strFileName = PictureManager.GetFileName("img_");
Random rnd = new Random();
strFileName += rnd.Next(111111, 999999).ToString() + FileExtension;
VertualUrl0 = VertualUrl0 + "\\" + strFileName;
string VertualUrl1 = SaveImgPath + "\\Medium";
//VertualUrl1 = Server.MapPath(VertualUrl1);
if (!Directory.Exists(VertualUrl1))
Directory.CreateDirectory(VertualUrl1);
VertualUrl1 = VertualUrl1 + "\\" + strFileName;
string VertualUrl2 = SaveImgPath + "\\Small";
//VertualUrl2 = Server.MapPath(VertualUrl2);
if (!Directory.Exists(VertualUrl2))
Directory.CreateDirectory(VertualUrl2);
VertualUrl2 = VertualUrl2 + "\\" + strFileName;
SaveImgPath += "\\" + strFileName;
fluImage.SaveAs(SaveImgPath);
PictureManager.CreateThmnail(SaveImgPath, 400, VertualUrl0);
PictureManager.CreateThmnail(SaveImgPath, 250, VertualUrl1);
PictureManager.CreateThmnail(SaveImgPath, 175, VertualUrl2);
}
else
{
if (Session["EditBannerID"] != null)
{
//int BannerID = 0;
//BannerID = Int32.Parse(Session["EditBannerID"].ToString());
if (imgEdit.ImageUrl != string.Empty)
{
string imgUrl = imgEdit.ImageUrl;
strFileName = imgUrl.Substring(imgUrl.LastIndexOf("/") + 1);
}
}
}
return strFileName;
}
示例14: UploadImage
/// <summary>
/// 取出客戶端上傳照片
/// </summary>
public void UploadImage(FileUpload myFileUpload, string filePath, int maxPx)
{
fileName = Guid.NewGuid().ToString(); // 亂數得要圖片的檔名
imageName = ""; // ex:檔名 1604151001.jpg
//是否允許上傳
bool fileAllow = false;
//設定允許上載的延伸檔名類型
string[] allowExtensions = { ".jpg", ".gif", ".png" };
//取得網站根目錄路徑 大圖先丟到delete資料夾
string path = HttpContext.Current.Request.MapPath("~/pic/delete/");
//檢查是否有檔案
if (myFileUpload.HasFile)
{
//取得上載檔案副檔名,並轉換成小寫字母
string fileExtension =
System.IO.Path.GetExtension(myFileUpload.FileName).ToLower();
//檢查副檔名是否符合限定類型
for (int i = 0; i < allowExtensions.Length; i++)
{
if (fileExtension == allowExtensions[i])
{
fileExtension = ".jpg";
fileAllow = true;
}
}
if (fileAllow)
{
try
{
//將 檔名 跟 附檔名存入 資料庫 設為路徑
imageName = fileName + fileExtension;
//儲存檔案到磁碟
myFileUpload.SaveAs(path + fileName + fileExtension); //路徑 + 檔名 + jpg/png
//maxPx 宣告一個圖片尺寸的設定值(Max寬度)
addImage(myFileUpload, filePath, fileExtension, maxPx);//將大圖縮小後 刪除 大圖 存小圖 //
}
catch (Exception)
{
}
}
}
}
示例15: SaveZhuanTiImage
//保存图片
private string SaveZhuanTiImage(FileUpload file, string zhuanTiImage, int ztId)
{
string fileName = file.FileName;
if (!ImageHelper.CanUpload(file.FileName))
{
Utility.Alert(this, "图片文件格式不支持!");
return "";
}
zhuanTiImage = ImageHelper.GetZhuanTiImageName(userId, ztId, fileName);
string imagePath = ImageHelper.GetZhuanTiImagePath(zhuanTiImage);
try
{
file.SaveAs(imagePath);
ImageHelper.SaveImage(imagePath, 200, 200);
}
catch
{
Utility.Alert(this, "专题图片上传失败!");
return "";
}
return zhuanTiImage;
}