本文整理汇总了C#中FileUpload.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# FileUpload.Focus方法的具体用法?C# FileUpload.Focus怎么用?C# FileUpload.Focus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUpload
的用法示例。
在下文中一共展示了FileUpload.Focus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadPhoto
/// <summary>
/// อัพโหลดภาพ พร้อมย่อขนาด
/// </summary>
/// <param name="fuPhoto"></param>
/// <param name="pathShort"></param>
/// <param name="photoName"></param>
/// <param name="errorMessage"></param>
/// <param name="outFileName"></param>
/// <param name="maxSizeKB"></param>
/// <param name="maxWidth"></param>
/// <param name="maxHeight"></param>
/// <param name="resizeAnchor"></param>
/// <param name="resizeMode"></param>
/// <param name="resizeFormat"></param>
/// <returns></returns>
/// <example>
/// clsIO clsIO = new clsIO();
/// string outErrorMessage;
/// string outFileName;
/// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName);
/// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,resizeFormat:clsIO.ResizeFormat.png);
/// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeFormat:clsIO.ResizeFormat.png);
/// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeMode:clsIO.ResizeMode.crop,resizeQuality:100);
/// </example>
public bool UploadPhoto(FileUpload fuPhoto, string pathShort, string photoName, out string errorMessage, out string outFileName, int maxSizeKB = 0, int maxWidth = 0, int maxHeight = 0, ResizeAnchor resizeAnchor = ResizeAnchor.middlecenter, ResizeMode resizeMode = ResizeMode.crop, ResizeFormat resizeFormat = ResizeFormat.original, int resizeQuality = 90)
{
bool rtnValue = true;
errorMessage = "";
outFileName = "";
if (fuPhoto.HasFile == true)
{
#region Error Checker
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;
}
}
#endregion
#region Out FileName
if (resizeFormat != ResizeFormat.original)
{
outFileName = photoName + "." + resizeFormat.ToString();
}
else
{
outFileName = photoName + System.IO.Path.GetExtension(fuPhoto.FileName).ToLower();
}
#endregion
FileExist(pathShort + outFileName, true);
#region Upload Photo
try
{
fuPhoto.SaveAs(System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName));
}
catch (Exception ex)
{
errorMessage = "เกิดข้อผิดพลาด ขณะอัพโหลดไฟล์ไว้ที่ " + System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName + "<br/>" + ex.Message);
fuPhoto.Focus();
return false;
}
#endregion
#region Resize Photo
try
{
#region Condition Builder
string resizeSetting = "";
if (maxWidth > 0)
{
if (resizeSetting.Length > 0) resizeSetting += "&";
resizeSetting += "width=" + maxWidth.ToString();
}
if (maxHeight > 0)
{
if (resizeSetting.Length > 0) resizeSetting += "&";
resizeSetting += "height=" + maxHeight.ToString();
}
if (resizeMode != ResizeMode.pad)
{
if (resizeSetting.Length > 0) resizeSetting += "&";
resizeSetting += "mode=" + resizeMode.ToString();
}
if (resizeAnchor != ResizeAnchor.middlecenter)
{
if (resizeSetting.Length > 0) resizeSetting += "&";
//.........这里部分代码省略.........