Pages

About Me

My photo
ForEach(Minute in MyLife) MyExperience ++;

Monday, July 11, 2011

Image save / retrieve/ extension / delete

==================================
image save
==================================

public string Save_Photo = HttpContext.Current.Server.MapPath("~/Upload/User_Photo/");
public string Get_Photo = "~/Upload/User_Photo/";

====================================
image retrieve
====================================
Img_USER_PHOTO.ImageUrl = clas.Get_Photo + dt.Rows[0]["USER_PHOTO"].ToString();


=====================================
Sub string
=====================================

Fup_USER_PHOTO.FileName.Substring(Fup_USER_PHOTO.FileName.LastIndexOf('.'));

====================================
delete image from folder
=====================================
System.IO.File.Delete(HttpContext.Current.Server.MapPath("~/images/") + DropDownList1.SelectedValue);

======================================
File search
=======================================
if (File.Exists(clas.Save_Photo + Photo_Del))
{
File.Delete(clas.Save_Photo + Photo_Del);
}

========================================
File extensions
========================================
if (fu.HasFile) // fu refers to FileUpload control.
{
String fileExtension = System.IO.Path.GetExtension(fu.FileName).ToLower();
String[] allowedExtensions = { ".jpg", ".gif", ".png" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
if (fileOk == true) { fu.SaveAs("path" + fu.FileName); }
}
}

No comments:

Post a Comment