我有一个项目网站使用我的CodeFile从本地浏览器照片然后保存路径文件图像数据库成功。但在我的开发人员项目主机,你不能插入路径文件图像到我的数据库。虽然本地机器上的项目运行得很好。 有人能帮我吗。 谢谢你们 这是我的大块代码:
HTML CODE:
<%@ Page Title="" Language="C#" MasterPageFile="~/ad/Admin.Master" AutoEventWireup="true" CodeFile="EditProduct.aspx.cs" Inherits="EditProduct" %>
<asp:Image ID="Image1" runat="server" Height="91px" Width="96px" />
<asp:FileUpload ID="FileUpload1" runat="server" /></td>
代码C#:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BAL;
using DAL;
protected void Insert()
{
Product product = new Product();
//Gan du lieu vao doi tuong
product.Pro_Keyword = txtKeyword.Value + " " + txtPro_Name.Value;
product.Pro_IsDiscount = chkKhuyenMai.Checked;
product.Pro_Price = int.Parse(txtPrice.Value);
product.Pro_Name = txtPro_Name.Value;
product.Pro_Warranty = txtWarranty.Text;
product.Pro_Condition = txtCondition.Text;
product.Title = txtTitle.Text;
product.Keyword = txtGoogle_Keyword.Text;
product.Description = txtDescription.Text;
product.Pro_Position = 0;
product.Pro_PriceDiscount = double.Parse(txtPriceDiscount.Value);
product.Pro_IsComment = true;
product.Pro_Content = HtmlEditor2.Text;
//product.Pro_Intro = HtmlEditor1.Text;
product.Pro_Intro = txtCode_Product.Text;
product.Cate_ID = int.Parse(ddlCategory.SelectedValue);
string _sFolder = Request.PhysicalApplicationPath.Replace(@"\", "/") + "/Images_Upload/Product/";
product.Pro_CreateDate = DateTime.Now;
if (string.IsNullOrEmpty(FileUpload1.FileName) == false)
{
product.Pro_Image = ExtendFunctional.UploadPicture(_sFolder, FileUpload1.PostedFile);
Image1.ImageUrl = "../Images_Upload/Product/" + product.Pro_Image;
}
//if (string.IsNullOrEmpty(FileUpload2.FileName) == false)
//{
// product.Pro_BigImage = ExtendFunctional.UploadPicture(_sFolder, FileUpload1.PostedFile);
// Image2.ImageUrl = "/Images/Products/" + product.Pro_BigImage;
//}
product.Pro_PriceDiscount = 0;
product.Pro_Status = true;
//Them moi
Product_BAL.Insert_Product(product);
Response.Write("<script>alert('Đã thêm mới thành công!') ; window.location.href='ManageProduct.aspx'</script>");
//MessageBox.Show("Đã thêm mới thành công.");
}
类ExtendFunctional:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class ExtendFunctional
{
public static bool IsNumberic(string str)
{
try
{
if (string.IsNullOrEmpty(str)) return false;
int i = Convert.ToInt32(str);
return true;
}
catch { return false; }
}
public static void DeleteImageInFolder(string path)
{
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
}
public static bool IsImageFile(string fileName)
{
try
{
string[] extend = new string[] { ".gif", ".bmp", ".jpg", ".jpeg", ".png" };
string ex = fileName.Substring(fileName.Length - 4).ToLower();
foreach (string s in extend)
if (s == ex) return true;
return false;
}
catch { return false; }
}
public static string UploadPicture(string _sFolder, HttpPostedFile _File)
{
string _sResult = "";
if (!System.IO.Directory.Exists(_sFolder))
System.IO.Directory.CreateDirectory(_sFolder);
string _sFileName = System.IO.Path.GetFileName(_File.FileName);
try
{
_File.SaveAs(_sFolder + "/" + _sFileName);
_sResult = _sFileName;
}
catch (Exception)
{
}
return _sResult;
}
}