Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
While Image saving to Server folder how to change Image name as Login name .


XML
Label1.Text = Session["UserName"].ToString();
<pre lang="cs">if (FileUpload1.HasFile)
            {
                fileName = FileUpload1.FileName;
                filePath = Server.MapPath(&quot;~/Images/&quot; + System.Guid.NewGuid() + fileName);
                FileUpload1.SaveAs(filePath);
                cmd.Parameters.AddWithValue(&quot;@image_Name&quot;, fileName);</pre>
Posted
Comments
[no name] 11-Jul-15 7:23am    
Your question is "how to change the filename variable to something else"?
Unni R 13-Jul-15 4:16am    
s. i need to change Filename as Login name
aarif moh shaikh 14-Jul-15 2:06am    
give the Label1.Text Value in place of filename variable
Unni R 14-Jul-15 5:24am    
how to replace Filename

1 solution

Try:
C#
Label1.Text = Session["UserName"].ToString();
if (FileUpload1.HasFile)
    {
    fileName = FileUpload1.FileName;
    filePath = Server.MapPath(Path.Combine("~/Images", Label1.Text, System.Guid.NewGuid().ToString() + fileName));
    FileUpload1.SaveAs(filePath);
    cmd.Parameters.AddWithValue("@image_Name", fileName);
But I'd suggest you might want to keep track of the GUID value if you want to find the file again...
 
Share this answer
 
Comments
Unni R 13-Jul-15 5:20am    
i need to change Filename as Login name. Below code is use to both login name and uploaded image name also showing
OriginalGriff 13-Jul-15 5:41am    
Do you want to try explaining that without assuming I know about your project and how it works?
Remember that we can't see your screen, access your HDD, or read your mind! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900