deleting images from gridview as well as folder also

Posted by Madhuri123 under Regular Expressions on 6/27/2011 | Points: 10 | Views : 9569 | Status : [Member] | Replies : 6
Hi, In my project i want delete a image from folder as well as Database also.I m deleting images from Database.iam unable to delete a images from folder

here i write a code for deleting images under a gridview event(RowDeleting() )


e.Cancel = true;
string fileName = ((Button)GridView1.Rows[e.RowIndex].FindControl("btnDelete")).Text;

fileName = Path.Combine(Server.MapPath("~/media/ul"), fileName);


File.Delete(fileName);
GridView1.DataBind();


but i want a code under the Rowcommand of the gridview
any one plz help me


Thanks inAdvance
T.Madhuri




Responses

Posted by: Karthikanbarasan on: 6/27/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Is your requirement to delete the image from the folder as soon as it deleted from the grid view????

Thanks
Karthik
www.f5Debug.net

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

Posted by: Madhuri123 on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
yes mr.Karthik

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

Posted by: Madhuri123 on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down

is it possible to delete images from folder under the Rowcommand?

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

Posted by: Ndebata on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can use File.Delete for this
<asp:TemplateField>

<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" CommandArgument='<% # Bind("IMPATH") %>' CommandName="Del" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>

In Code behind file
void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{
try
{
if (e.CommandName == "Del")
{
File.Delete(Server.MapPath(e.CommandArgument.ToString()));
BindGridView();
}
}
catch (Exception ex)
{
}
}





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

Posted by: Vforvijay on: 6/28/2011 [Member] Starter | Points: 25

Up
0
Down
hi..try this link hope it helpful to you
http://vbdotnetaddict.blogspot.com/2011/06/how-to-store-imageurl-in-database-and.html

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

Posted by: Ajay_Devloper on: 3/1/2012 [Member] Starter | Points: 25

Up
0
Down
great job...
provide good ideas and the code is running well.
thanks..

ajay singh gusain
.net developer

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

Login to post response