如何在数据库中保存图片路径,然后使用openFile对话框进行检索 [英] how to save a picture path in database and then retrive using openFile Dialog

查看:89
本文介绍了如何在数据库中保存图片路径,然后使用openFile对话框进行检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我有一个窗口窗体,其中包含有关该项目的一些信息,但它也包含一个图片框以显示该项目的图片...我使用openfile对话框成功地将图片添加到此图片框中,但是.....

Openfile对话框存储在数据库中时选择的路径,因此没有文件扩展名....(我的意思是说文件扩展名即.JPEG等.)


因此,当我再次打开该表格时,它给出了一个错误,即文件路径不正确.... picturebox无法在由openfile对话框存储的特定路径的基础上加载该图片...

所以我该怎么办???


Muhammad Tufail

Hello to all...

i have a window Form which cotains some information about the item but it also cotains a picture box to show the picture of that item... i successfully add a picture to this picturebox using openfile dialog but .....

the path that is picked by the openfiledialog when stored in database so it is withoud of File Extension.... ( i mean to say that File Extension i.e .JPEG etc..)


so when i open again that form so it gives an error that the file path is not a correct.... picturebox can not load that picture on the bases of that particular path stored by openfile dialog...

so what i should do please????


Muhammad Tufail

推荐答案

OpenFileDialog返回完整的文件名,如果您读取FileName属性,则包括路径和扩展名.
OpenFileDialog returns the full file name, including path and extension if you read the FileName property.
OpenFileDialog o = new OpenFileDialog();
o.ShowDialog();
Console.WriteLine(o.FileName);


因此,您要么无法保存自己认为在数据库中的内容,要么就无法从数据库中正确读取文件并打开文件.
您正在使用什么代码来获取文件名并将其保存在数据库中?



非常感谢....我已经通过(safeFileName)有了这个主意...现在它可以正常工作.....
但是,如果我想将此图片存储在本地文件夹中(我是说要在当前项目正在运行的那个文件夹中)...
那我该怎么办? 我应该使用SaveFileDialogBox ?????"


仅当您希望用户选择将其保存在哪里时(这不是一个坏主意,尝试将其保存到应用程序文件夹中会充满权限问题).我会将其保存到应用程序数据文件夹 [


So either you can''t be saving what you think you are in the database, or you aren''t reading it from the database correctly and opening the file.
What code are you using to get the file name and save it in the database?



"Thanx very much.... i have got the idea through (safeFileName) ... Now its work properly.....
But if i want to store this picture in a local folder ( i mean to say that in that folder where the project is currently running )...
then what i should do ????
should i use SaveFileDialogBox ?????"


Only if you want the user to select where to save it (not a bad idea, trying to save to the application folder is fraught with permission problems). I would save it to the application data folder[^] instead, myself.

Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));


SaveFileDialog框只会为您提供保存文件的路径-不会进行将图像的内存流转换为实际文件所需的转换.

但是,
此处 [
SaveFileDialog box will only give you the path to save the file - it will not do the conversion you would need to convert the memory stream of the image to the actual file.

However, here[^] is a good sample for SaveFileDialog.


这篇关于如何在数据库中保存图片路径,然后使用openFile对话框进行检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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