本文介绍了在C#WinForm App中将图像存储在服务器硬盘上的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 就我而言,将图像直接存储在SQL DB中并不是最好的方法。特别是当它们有很多具有巨大空间的时候。专家声称,将图像名称插入数据库并将图像存储在H盘上会更好。 所以,我写了一些代码,如下所示,保存图像用户计算机的H盘: private void btnSave_Click( 对象 sender, EventArgs e) { string imageName = Guid .NewGuid()。ToString()+ 路径 。GetExtension(PicBoxCustomer.ImageLocation); string path = Application.StartupPath + " / Images /" ; if (! 目录 。Exists(path)) {/ / span > 目录 。CreateDirectory(path); } PicBoxCustomer.Image.Save(path + imageName); 客户customers = new 客户() {/ / span >          &NBSP ; Mobile = txtMobile.Text,                     CustomerImage = imageName }; if (customerId == 0) {/ / span > db.CustomerRepository.InsertCustomer(customers); } 其他 {/ / span >                     customers.CustomerID = customerId;                     db.CustomerRepository.UpdateCustomer(customers); } db.Save( ); } } 这适用于单个用户,但在现实世界中,我的公司有大约1300名人员(用户),我必须找到一种方法来保存 "服务器的硬盘 "不在每个用户的计算机上(以便能够向所有用户显示所有图像)。 我有两个问题: 1-我应该如何通过内联网将图像从用户的PC传输(上传)到服务器? 2-如何更改以上代码以将图像保存在服务器硬盘而不是用户的计算机上? (我正在使用具有Repository设计模式的LINQ技术(DataContext)) 你能帮我做那个吗? 解决方案 您好, 我建议Admin为用户子目录 应用程序访问以查看和保存选项。管理员应限制删除和 服务器上的其他文件/目录操作。您可以使用数据库来跟踪用户和 图片文件信息,用于良好的家务管理。 或者最容易/最简单的是让用户从客户端上的资源管理器访问服务器映像目录/文件存储作为网络 文件夹/驱动器。您仍然可以设置组策略限制。这也 意味着更少的节目和更多的管家保持。 希望这会有所帮助:)Hi every one,As far as I'm concerned, storing images directly in an SQL DB is not the best way. Specially, when there are lots of them with huge space. Experts claim that it’s better to just insert the images name into DB and store images on the H-Disk.So, I wrote some codes like below which saves images on the H-Disk of the users’ computer:privatevoid 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(); } }This works fine for a single user, but in the real world, my company has about 1300 personnel (users) and I must find a way that saves images on theServer’s Hard-Disk not on every users’ computer (to have the ability of showing all images to all users).I have two questions:1- How should I transfer (upload) images from user's PC via intranet to the server?2- How should I change above codes to save images on the server hard-disk instead of user's computer?(I’m using LINQ technology (DataContext) with Repository design pattern)Would you please help me to do that? 解决方案 Hello, I suggest that Admin create directory structure for image files root with User sub-directorywith read/write group policy access rights for Server side storage. On User side create anapplication with network access for view and save options. Admin should restrict delete andother file/directory operations on the server. You can use the DB just to track the User andimage file info for good house keeping practices. Or the most easy/simple is let User access the Server image directory/file storage as a Networkfolder/drive from Explorer on the Client. You can still setup group policy restrictions. This alsomeans less programming and more house keeping for Admin. Hope this helps :) 这篇关于在C#WinForm App中将图像存储在服务器硬盘上的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 13:54