上传图片和显示的问题 [英] problem with Upload picture and display

查看:95
本文介绍了上传图片和显示的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



我写了以下代码用于上传图片然后立即显示,





Hi.

I have written the following code for uploading the image and then dispaly it instantly,


protected void SendImageButton_Click(object sender, EventArgs e)
        {
            string ImageName = FileUpload.FileName.ToString();
            string ImagePath = "/~ImageStorage/" + ImageName;
            FileUpload.SaveAs(Server.MapPath(ImagePath));

            int ImageSize = FileUpload.PostedFile.ContentLength;

            if (FileUpload.PostedFile != null && FileUpload.PostedFile.FileName != "")
            {
                SqlCommand Command = DataProvider.GenerateCommand("[dbo].[Insert_UploadPicture_SP]", CommandType.StoredProcedure);
                Command.Parameters.AddWithValue("@IdCode", GlobalVariables.IdCode);
                Command.Parameters.AddWithValue("@ImagePath", ImagePath);
                Command.Parameters.AddWithValue("@ImageName", ImageName);
                Command.Parameters.AddWithValue("@ImageSize", ImageSize);

                try
                {
                    Command.Connection.Open();
                    Command.ExecuteNonQuery();
                    Command.Connection.Close();
                }
                catch (Exception ex)
                {
                    EventLogger.Log(ex.Message, LogType.Error);
                }
                finally
                {
                    DataProvider.DisposeCommand(Command);
                }
            }

        }







但当我按下发送按钮时会抛出此异常:



DirectoryNotFoundException未被用户代码处理。

找不到路径的一部分''E:\ BackUp \VisualStudio2010\Marashi910816\Marashi \〜ImageStorage\Lighthouse.jpg''。




你能告诉我如何修改代码以立即显示图像?因为这个图像既不插入也不显示。




but when i press the Send button this exception is thrown :

DirectoryNotFoundException was unhandled by user code.
Could not find a part of the path ''E:\BackUp\VisualStudio2010\Marashi910816\Marashi\~ImageStorage\Lighthouse.jpg''.


and would you please tell me how can i modify the code to display the image instantly? becacuse this image neither is inserted and nor is displayed.

推荐答案







请查看以下链接:



例外情况:从Imagepath中删除波浪号码。



http://aspsnippets.com/Articles/Upload-images-to-folder-and-display-uploaded-images-in-ASPNet-GridView-using-C-and-VBNet.aspx [< a href =http://aspsnippets.com/Articles/Upload-images-to-folder-and-display-uploaded-images-in-ASPNet-GridView-using-C-and-VBNet.aspx\"target =_ blank title =新窗口> ^ ]



http://geekswithblogs.net/dotNETvinz/archive/2011/01/20/uploading-image-to-一个文件夹,并显示最图像after.a spx [ ^ ]


这篇关于上传图片和显示的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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