如何使用asp.net保存数据库中的图像路径 [英] how to save path of image in database using asp.net

查看:81
本文介绍了如何使用asp.net保存数据库中的图像路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends



我想使用asp.net(c#)在sql server 2005中保存图像路径。我也在我的应用程序中使用文件上传控件。

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.

推荐答案

这里你去



上传和存储数据库的图像路径图像到文件夹 - 第1部分 [ ^ ]



上传和存储数据库和图像到文件夹的图像路径 - 第2部分 [ ^ ]
Here you go

Uploading and Storing Image Path to Database and Image to Folder - Part 1[^]

Uploading and Storing Image Path to Database and Image to Folder - Part 2[^]


试试这个

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


使用Server.MapPath(文件名)访问文件

使用FileUpload1.SaveAs(带路径的文件)保存文件

将文件名+路径存储到数据库中。
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.


这篇关于如何使用asp.net保存数据库中的图像路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆