0

hi all, i'm going to make an upload picture into database.. in run successfully but now it will store as

C:\Users\itdept\Desktop\webmaster\image\Desert.jpg

but i just want to make it like this

~/image/Desert.jpg

is it possible?

5
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by __avd
0

C:\Users\itdept\Desktop\webmaster\image\Desert.jpg
Is it your client computer right?
Do you use asp:fileupload?

Another solution: You can split this string and you can get just one you need.
Here is:

string[] path = fileupload.Postedfile.filename.split('/');
0

thanks for ur response..
yes, it is client computer and i'm using file asp:upload..

if i make it like you suggest, the path in my db is like this

System.String[]

is it true?

actually..my previous post is not clearly define what actually i need..
1) how to make the splitter from '\' to '/'
2) how to make a short path '~/image/Desert.jpg' instead of 'C:\Users\itdept\Desktop\webmaster\image\Desert.jpg'

the coding now is like this

protected void btnUpload_Click(object sender, EventArgs e)
    {
        string strDescription = txtName.Text.ToString();
        if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
        {
            byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];
            HttpPostedFile uploadedImage = FileUpload1.PostedFile;
            uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
            //string ImagePath = FileUpload1.PostedFile.FileName;
            //string ImagePath = Server.MapPath("~/image/" + FileUpload1.FileName);
            string[] ImagePath = FileUpload1.PostedFile.FileName.Split('/');
            SqlConnection con = new SqlConnection("Server=(local); Database=test; user id=sa; password=itdept");

            // Create SQL Command 
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "INSERT INTO image(imageView,Description,imagePath)" + " VALUES (@imageView,@Description,@imagePath)";
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;

            SqlParameter Description = new SqlParameter("@Description", SqlDbType.VarChar, 50);
            Description.Value = strDescription.ToString();
            cmd.Parameters.Add(Description);

            SqlParameter UploadedImage = new SqlParameter ("@imageView", SqlDbType.Image, imageSize.Length);
            UploadedImage.Value = imageSize;
            cmd.Parameters.Add(UploadedImage);

            SqlParameter imagePath = new SqlParameter("@imagePath", SqlDbType.NVarChar, 50);
            imagePath.Value = ImagePath.ToString();
            cmd.Parameters.Add(imagePath);

            con.Open();
            int result = cmd.ExecuteNonQuery();
            con.Close();
            if (result > 0)
            lblMessage.Text = "File Uploaded";
            GridView1.DataBind();
        }
    }

Edited by new SE: n/a

0

It can be possible only in Asp.net not in RDBMS like SQL serveror My SQL. They will take full path like C:\Users\itdept\Desktop\webmaster\image\Desert.jpg.

-1

Hi..

i upload script that uploads images to the server and sends the image path to the database.

<?php

mysql_connect("localhost", "xxx", "xxxxx") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());

$result = mysql_query("SELECT * FROM bild ");




echo "<table border='1' width=400px>
<tr>
<th></th><br />

<th></th>
<th></th>

</tr>";while($row = mysql_fetch_array($result)) {
echo "<tr >";
echo " posted by <tr class=trow>" . $row['name'] . "</td>";
echo " <tr class=trow3>" . $row['imagepath'] . "</td>";




echo "</tr class=>";
}
echo "</table>";mysql_close($con);
?>

It will help you.

Edited by __avd: Added [code] tags.

Votes + Comments
Please read the question before you post anything. Read member rules please.
0

@crishjeny

Please do not resurrect threads that are years old. By doing so you run the risk of confusing current posters. If you have any questions please ask. You are welcome to start your own threads. Have a look at forum rules.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.