Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello Friends

I want to save image path in sql server 2005 using asp.net(c#). I also use file upload control in my application.
Posted

 
Share this answer
 
Comments
Espen Harlinn 15-Mar-11 15:00pm    
Have you checked part 2?
thatraja 15-Mar-11 15:05pm    
what happened? any issues?
Espen Harlinn 15-Mar-11 15:26pm    
check out the page for part 2, it doesn't contain anything useful - just thought I'd let you know :)
thatraja 15-Mar-11 21:46pm    
actually it's 2nd part of the page so I have included that. Anyway thanks Espen.
:)
Espen Harlinn 16-Mar-11 3:57am    
I know, I just thought you might like to remove it, you have my 5 though :)
try this
C#
protected void btnSub_Click(object sender, EventArgs e)
   {
       try
       {
           string filename = FileUpload1.FileName;

           FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploadform\\" + filename.Trim()));

           string path = "~\\Uploadform\\" + filename.Trim();

           SqlConnection con = new SqlConnection(str);
           cmd = new SqlCommand("Insert into Circular(title,type,url1) values('" + txttitle.Text + "','" + txttype.Text + "','" + path + "')", con);
           lblinfo.Text = " Uploaded Successfully ";
           cmd.CommandType = CommandType.Text;
           con.Open();
           cmd.ExecuteNonQuery();
           con.Close();
       }
       catch (Exception ex)
       {
           Response.Write(ex.ToString());
       }
   }
 
Share this answer
 
v2
Use Server.MapPath("File Name") For Accessing File
Use FileUpload1.SaveAs("File With Path") for Saving File
Store the File Name + Path in to Database.
 
Share this answer
 
Assuming your two questions are connected, i.e. you want to use a file upload control in a web application and store the original file path in your database, then the bad news is: you can't.

The original path is not passed through to the server by the file upload control for two reasons:
1) Security: it would give information about the client system to teh server, no matter how trivial.
2) Irrelevance: The original path is not relevant to the server as it has no access to the client drives, logical or real.

If that is not what you are trying to do, what is?
 
Share this answer
 
 
Share this answer
 
 
Share this answer
 
THANX SIR IT HELPS ME ALOT FOR BEGINNER
 
Share this answer
 
Comments
[no name] 9-Oct-14 6:58am    
If it helped you a lot, why are you screaming? How is this a solution to this ancient posting anyway?
Please Use these Links to reduce your Problem.

Storing and Retrieving Images from SQL Server using Microsoft .NET[^]

Store or Save images in SQL Server[^]


Thanks
AARIF SHAIKH
 
Share this answer
 

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