Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 11-Mar-11 21:09pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Espen Harlinn at 15-Mar-11 15:00pm
   
Have you checked part 2?
thatraja at 15-Mar-11 15:05pm
   
what happened? any issues?
Espen Harlinn at 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 at 15-Mar-11 21:46pm
   
actually it's 2nd part of the page so I have included that. Anyway thanks Espen.
:)
Espen Harlinn at 16-Mar-11 3:57am
   
I know, I just thought you might like to remove it, you have my 5 though :)
thatraja at 16-Mar-11 11:43am
   
Thanks Espen *snow*
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

try this
 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());
        }
    }
 

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

THANX SIR IT HELPS ME ALOT FOR BEGINNER
  Permalink  
Comments
Wes Aday at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 10 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100