解决方案 »
- 送分,VS2008下js代码能像c#一样折叠吗?
- 请问一个iframe的问题
- 急,请求帮助...关于treeview节点的索引问题
- GridView or DataGrid列头设置问题
- 如何在PlaceHolder1.Controls里进行输入空格和线
- 请教一个Asp.net高级应用问题:怎么样封装一个TextBox控件和一个javascript函数?
- Web项目无法访问网络映射驱动器
- 电子地图应用例子,可以随意调用,建立自己的应用...
- 如何知道LDAP的帮定路径参数 类似于 LDAP://cn=..,DC=test,DC=com
- ASP.NET怎么运行,怎么配制那?
- asp.net中上传文件到FTP上,远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。
- 帮看一下, 网站是不是被人攻击?
如果需要保存,确保你的asp.net运行account:NETWORK SERVICE(IIS6下)有对target目录的读写权限。
而且你本机应该有那个目录。
/// 上传图片保存
/// </summary>
/// <param name="UrlName">图片地址</param>
/// <param name="ImageName">保存数据库名称(自定义的)</param>
private void Bave_UploadImage(string UrlName, string ImageName)
{
string type = UrlName.Substring(UrlName.LastIndexOf(".") + 1);
FileStream fs = File.OpenRead(UrlName);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
//保存数据库
DBHelp.UploadImage(this.txtJcCode.Text, content, 100, ImageName, type);
}
哪里保存的?这里是读取。保存,没有异常吗?
FileStream fs = File.OpenRead(UrlName);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
{
//打开数据库连接
objSqlConnection.Open();
bool result = false;//定义一个返回变量,初值为false
try
{
SqlCommand cm = new SqlCommand("INSERT INTO dbo.UploadImage(JcCode,Bytes,Size,ImageName,ImageType)VALUES(@JcCode,@Bytes,@Size,@ImageName,@ImageType)", objSqlConnection);
cm.Parameters.Add("@JcCode", SqlDbType.VarChar);
cm.Parameters["@JcCode"].Value = JcCode;
cm.Parameters.Add("@Bytes", SqlDbType.Image);
cm.Parameters["@Bytes"].Value = content;
cm.Parameters.Add("@Size", SqlDbType.VarChar);
cm.Parameters["@Size"].Value = Size.ToString();
cm.Parameters.Add("@ImageName", SqlDbType.VarChar);
cm.Parameters["@ImageName"].Value = ImageName;
cm.Parameters.Add("@ImageType", SqlDbType.VarChar);
cm.Parameters["@ImageType"].Value = Type;
int n = cm.ExecuteNonQuery();
objSqlConnection.Close();
if (n > 0)
{
result = true;
} }
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
finally
{
objSqlConnection.Close();
}
return result;
因此估计你保存的路径和读取的路径不同了。之后还没有走到,和你目前的问题没有关系。
if (this.FileUpload1.HasFile)
{
string IsXls = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower();
if (IsXls != ".xls")
{
MessageBox.Show("本程序只能识别excel文件!",this);
return;
}
xlsName = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss")+System.IO.Path.GetFileName(FileUpload1.FileName) ; // string filename = this.FileUpload1.PostedFile.FileName.ToString().Trim(); DataTable dt = new DataTable();
int len = this.FileUpload1.FileName.ToString().Trim().Length; string path = Server.MapPath("../UpLoad/") + xlsName;
this.FileUpload1.SaveAs(path); //上传文件
/// 上传图片保存
/// </summary>
/// <param name="UrlName">图片地址</param>
/// <param name="ImageName">保存数据库名称(自定义的)</param>
private void Bave_UploadImage(string UrlName, string ImageName)
{
string type = UrlName.Substring(UrlName.LastIndexOf(".") + 1);
FileStream fs = File.OpenRead(UrlName);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
//保存数据库
DBHelp.UploadImage(this.txtJcCode.Text, content, 100, ImageName, type);
}你这个是上传? <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传"
style="height: 21px" />
protected void Button1_Click(object sender, EventArgs e)
{
byte[] bt = FileUpload1.FileBytes;
Response.Clear();
Response.ContentType = "image/gif";
Response.BinaryWrite(bt);
}FileUpload1直接有保存方法
FileUpload1.SaveAs("保存地址");
Could not find a part of the path 'D:\司机信息照片\DSCN0228.JPG'
数据库保存地址不就好了,访问时查看地址不就好了,保存在数据库貌似没人用吧,这样要是有问题找都麻烦了.换换试试,
{
if(FileUpload1.HasFile)
{
string productName = txtProductName.Text;
byte[] productImage = FileUpload1.FileBytes; string constr = "Server=TestServer; Database=SampleDB; uid=sa; pwd=abc123";
string query = "INSERT INTO Products(ProductName, ProductImage) VALUES(@ProductName, @ProductImage)"; SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con); com.Parameters.Add("@ProductName", SqlDbType.NVarChar).Value = productName;
com.Parameters.Add("@ProductImage", SqlDbType.VarBinary).Value = productImage; con.Open();
int result = com.ExecuteNonQuery();
con.Close(); if (result > 0)
{
lblMessage.Text = "Product Saved Successfully";
}
}
else
{
lblMessage.Text = "Please Select Product Image File";
}
}
请教如设置下权限,有具体步骤不。请指教。
权限的话,我的因为是内部服务器,所以我赋的是Users的权限。》右键 在你服务器上你要上传图片的那个文件夹>安全>然后设置一下
请教如设置下权限,有具体步骤不。请指教。
权限的话,我的因为是内部服务器,所以我赋的是Users的权限。》右键 在你服务器上你要上传图片的那个文件夹>安全>然后设置一下我不是上传到固定文件夹,而是直接读取客户端上传图片路径,转换成二进制流保存到表字段。
请教如设置下权限,有具体步骤不。请指教。
权限的话,我的因为是内部服务器,所以我赋的是Users的权限。》右键 在你服务器上你要上传图片的那个文件夹>安全>然后设置一下我不是上传到固定文件夹,而是直接读取客户端上传图片路径,转换成二进制流保存到表字段。如果能这么干的话,不知道会有多少肉鸡呢?
你是将本地图片的路径保存在数据库中吗?还是 将图片进行二进制转换,存储到IMAGE数据类型的字段中?
存路径的话肯定不行,路径是你本机的绝对路径,别人肯定看不到;存的是Image信息的话,应该是没有问题的。//获取图片的二进制流
FileStream fs = new FileStream(fileSaveURL, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close(); fs.Close();
//把图片写到数据库中
string conn = @"Data Source=JNITDEV\SQLEXPRESS;Initial Catalog=Picture;Integrated Security=True";
using (SqlConnection sqlConn = new SqlConnection(conn)) {
SqlCommand sqlComm = new SqlCommand();
sqlConn.Open();
sqlComm.Connection = sqlConn;
sqlComm.CommandText = "INSERT INTO Picture (PictureContent, PictureText) VALUES (@Picture,'Test')";
sqlComm.CommandType = CommandType.Text;
sqlComm.Parameters.Add("@Picture", SqlDbType.Image,photo.Length).Value = photo;
sqlComm.ExecuteNonQuery();
}
}
PictureID int 4, PictureContent Image, PictureText nvarchar(50)