upload and download image

Posted by Srinu0411 under ASP.NET on 6/19/2008 | Views : 1523 | Status : [Member] | Replies : 1
upload and download image to a folder

kaja srinivas


Responses

Posted by: Dongavipul on: 6/19/2008 [Member] Starter

Up
0
Down
For upload any image to folder
-----------------------------
//This function return file name (like id.exttention)
private string CompanyLogoUpload(string strPhotoId)
{
string strCompanyLogoFileName = "";
bool bIsExit = false;

if (fuPhoneImage.HasFile)
{
strCompanyLogoFileName = strPhotoId.ToString() + Path.GetExtension(fuPhoneImage.FileName.ToString());

// check that "company" floder exit or not
if (Directory.Exists(Server.MapPath("../DataImage")))
{
// check that particular company's (Use company id) floder exit or not
if (Directory.Exists(Server.MapPath("../DataImage/Manufacture")))
{
//Delte pervious file for that company
if (ViewState["LogoFileName"].ToString() != "NoImage")
{
File.Delete(Server.MapPath("../DataImage/Manufacture/" + ViewState["LogoFileName"].ToString()));
}
bIsExit = true;
}
else
{
// Create particular company's (Use company id) floder
Directory.CreateDirectory(Server.MapPath("../DataImage/Manufacture"));
bIsExit = true;
}
}
else
{
// Create main directory "company"
// then create company's (Use company id) floder in that logo floder
Directory.CreateDirectory(Server.MapPath("../DataImage"));
Directory.CreateDirectory(Server.MapPath("../DataImage/Manufacture"));
bIsExit = true;
}

if (bIsExit)
{
// Save upload logo file in particular directory
fuPhoneImage.SaveAs(Server.MapPath("../DataImage/Manufacture/" + strCompanyLogoFileName.ToString()));
}
}
return strCompanyLogoFileName;
}


Download image to folder
------------------------

bool bFileExit = false;

if (drManufacture["Image"] != null)
{
if (drManufacture["Image"].ToString() != "")
{

if (File.Exists(Server.MapPath("../DataImage/Manufacture/" + drManufacture["Image"].ToString())))
{
imgPhone.ImageUrl = "../DataImage/Manufacture/" + drManufacture["Image"].ToString();
ViewState["LogoFileName"] = drManufacture["Image"].ToString();
bFileExit = true;
}
}
}

if (!bFileExit)
{
imgPhone.ImageUrl = "../DataImage/Manufacture/No_Compnay_Logo.gif";
}

bFileExit = false;


Srinu0411, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response