将图像上传到数据库并从数据库显示在应用程序中 [英] Uploading images into database and displaying in the application from database

查看:62
本文介绍了将图像上传到数据库并从数据库显示在应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这是我的文件上传代码
-------------------------------


this my my file uploading code
-------------------------------

protected void Upload_MainImage(object sender, EventArgs e)
      {
          if (BrandUploadImg.HasFile)
          {
              //ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('File Detected');", true);
              BrandUploadImg.SaveAs(MapPath("/PRODIMAGES/" + BrandUploadImg.FileName));
              System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("/PRODIMAGES/") + BrandUploadImg.FileName);
              NormalImage.ImageUrl = "/PRODIMAGES/" + BrandUploadImg.FileName;
              
          }
          UpdatePanel7.Update();
         
      }


这用于将图像文件插入数据库中
===========================================


This for inserting imagefile into database
=============================================

if (NormalImage.ImageUrl != "")
                        {
                            string imagename = Path.GetFileName(BrandUploadImg.FileName);

                            string filename = Path.GetFileName(BrandUploadImg.FileName);
                            //Server.MapPath("MyVirtualDirectory")
                            string srvpat = Server.MapPath("/PRODIMAGES/") + filename;
                            if (!File.Exists(Server.MapPath("/PRODIMAGES/") + filename))
                                BrandUploadImg.SaveAs(Server.MapPath("/PRODIMAGES/") + filename);
                            string uploadfilename = NormalImage.ImageUrl;




-------------------------------------------------- ------------
但它显示了类似
的错误 1.找不到文件路径,例如D:\ folder \ ...
2.该进程无法访问文件''D:\ .....,因为它正在被另一个进程使用.



如何解决这些问题,请任何人帮助我.
在此先感谢




--------------------------------------------------------------
But it shows the errors like
1.Could not find a file path like D:\folder\...
2.The process cannot access the file ''D:\..... because it is being used by another process.



how to solve these problems,anybody help me please.
Thanks in advance

推荐答案

first of you you have to check where you are trying this application..
in your local pc or in server?

if in local pc then you need to check whether the application is in c or not because for some security reason win7 does not allow to access completely c drive or windows drive; so change application path to another drive.
If it is in server you have to check that file access permission are granted or not if not ask your administrator to give access to the image folder path.

Your code seems good...no problem over there..chek what i mentioned...
If still problem please share without hesitating.


您好,

在您的代码段中,我看不到任何与数据库相关的内容.希望您尝试将图像上传到服务器,然后应确保D驱动器PRODIMAGES文件夹具有写权限...


谢谢!!!
Hello,

I couldn''t see any data base related things in your code snippet. I hope you are trying to upload image to the server, Then you should ensure D drive PRODIMAGES folder has write permission...


Thanks!!!



感谢您的快速重播.
我通过从代码中删除以下三行并在上传图像后放置BrandUploadImg.Dispose()方法来解决了此问题.

================================================== =======================
BrandUploadImg.SaveAs(MapPath("/PRODIMAGES/" + BrandUploadImg.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("/PRODIMAGES/")+ BrandUploadImg.FileName);
Hi,
Thanks for your quick replay.
I solved this problem by removing the below three lines from code and also place BrandUploadImg.Dispose() method after uploading the image.

===========================================================================
BrandUploadImg.SaveAs(MapPath("/PRODIMAGES/" + BrandUploadImg.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("/PRODIMAGES/") + BrandUploadImg.FileName);


这篇关于将图像上传到数据库并从数据库显示在应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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