Hi eswardatta,
You can't rename the image when upload. We can change file name by using FileUpload control's SaveAs method. SaveAs() method require to pass a parameter named filename. This parameter value is a string that specifies the full path of the location of the server on which to save the uploaded file. using this parameter we can pass a new file name instead client uploaded file name.
Check this example. Now please take its reference and correct your code.
HTML
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClick="Upload" Text="Upload" />
Code
C#
protected void Upload(object sender, System.EventArgs e)
{
string path = Server.MapPath("~/Images/");
if (fuUpload.HasFile)
{
string extension = System.IO.Path.GetExtension(fuUpload.PostedFile.FileName);
fuUpload.SaveAs(path + "NewName" + extension);
}
}
VB.Net
Protected Sub Upload(ByVal sender As Object, ByVal e As System.EventArgs)
Dim path As String = Server.MapPath("~/Images/")
If fuUpload.HasFile Then
Dim extension As String = System.IO.Path.GetExtension(fuUpload.PostedFile.FileName)
fuUpload.SaveAs(path & "NewName" & extension)
End If
End Sub
The image will be saved in the Projects Image folder with the specified name.