就我而言,直接在SQL DB中存储图像并不是最好的方法。特别是当它们有很多具有巨大空间的时候。专家声称,最好只将图像名称插入数据库并将图像存储在H盘上。
所以,我写了一些如下所示的代码,用于将图像保存在用户计算机的H盘上:
private void btnSave_Click(object sender, EventArgs e)
{
string imageName = Guid.NewGuid().ToString() + Path.GetExtension(PicBoxCustomer.ImageLocation);
string path = Application.StartupPath + "/Images/";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
PicBoxCustomer.Image.Save(path + imageName);
Customers customers = new Customers()
{
Address = txtAddress.Text,
Email = txtEmail.Text,
FullName = txtName.Text,
Mobile = txtMobile.Text,
CustomerImage = imageName
};
if (customerId == 0)
{
db.CustomerRepository.InsertCustomer(customers);
}
else
{
customers.CustomerID = customerId;
db.CustomerRepository.UpdateCustomer(customers);
}
db.Save();
}
这适用于单个用户,但在现实世界中,我的公司有大约1300名人员(用户),我必须找到一种方法来保存服务器硬盘上所有用户PC的图像(不是每个用户的计算机上)分开,具有向所有用户显示所有图像的能力)。
我有两个问题:
我正在使用具有存储库设计模式的LINQ技术(DataContext
)。
你能帮帮我吗?
您在本主题中提出了多个问题,并且没有说明您的尝试和失败。
对于线索,您应该编写向客户端提供API的Web服务,以将图像上传到服务器并在服务器本地存储主题,搜索WCF或WebAPI以在C#中实现Web服务。