Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is not an error but image is not getting uploded. plz help me....

File Not Supporting For ImageSystem.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Winter.jpg'. File name: 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Winter.jpg' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at BrowseImage.UIUtilities.ReadImageFile(String PostedFileName, String[] filetype) in e:\prashantcs\executed\Corporate Management\CorporateBasedCredential Cluster\UserControls\BrowseImage.ascx.cs

C#
protected void btnShowImg_Click(object sender, EventArgs e)
    {
        HttpPostedFile postFile = this.Upload1.PostedFile;
        string strFileName = this.Upload1.FileName;
        try
        {
            if (this.Upload1.PostedFile != null)
            {

                //Check the selection of file
                if (string.IsNullOrEmpty(postFile.FileName))
                    lblMessage.Text = "Please select image to view";
                else
                {
                    //Get binary value of the image file
                    imageData = UIUtilities.ReadImageFile(postFile.FileName, new string[] { ".gif", ".jpg", ".bmp", ".jpeg" });
                    if (imageData == null)
                    {
                        lblMessage.Text = "Please select a file of format gif, jpg or bmp.";
                        imgMyPhoto.Attributes.Add("Src", "");
                    }
                    else
                    {
                        //persist the extension of the selected image file
                        //this.Page.RegisterHiddenField("hdnPhoto", Path.GetExtension(postFile.FileName));
                        Session["FileName"] = strFileName;
                        if (Session["Photo"] == null)
                            Session.Add("Photo", imageData);
                        else
                            Session["Photo"] = imageData;
                        imgMyPhoto.Attributes.Add("Src", Upload1.PostedFile.FileName);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
        }
    }


[edit]Code copied from OP comment - OriginalGriff[/edit]
Posted
Updated 14-Apr-12 21:03pm
v2
Comments
Prasad CM 15-Apr-12 2:51am    
can u please share ur code.. so that we can analyze ur code and we can find solution ....
Member 8388026 15-Apr-12 2:56am    
k fine i'll share it
Member 8388026 15-Apr-12 2:57am    
protected void btnShowImg_Click(object sender, EventArgs e)
{
HttpPostedFile postFile = this.Upload1.PostedFile;
string strFileName = this.Upload1.FileName;
try
{
if (this.Upload1.PostedFile != null)
{

//Check the selection of file
if (string.IsNullOrEmpty(postFile.FileName))
lblMessage.Text = "Please select image to view";
else
{
//Get binary value of the image file
imageData = UIUtilities.ReadImageFile(postFile.FileName, new string[] { ".gif", ".jpg", ".bmp", ".jpeg" });
if (imageData == null)
{
lblMessage.Text = "Please select a file of format gif, jpg or bmp.";
imgMyPhoto.Attributes.Add("Src", "");
}
else
{
//persist the extension of the selected image file
//this.Page.RegisterHiddenField("hdnPhoto", Path.GetExtension(postFile.FileName));
Session["FileName"] = strFileName;
if (Session["Photo"] == null)
Session.Add("Photo", imageData);
else
Session["Photo"] = imageData;
imgMyPhoto.Attributes.Add("Src", Upload1.PostedFile.FileName);
}
}
}
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
}
Member 8388026 15-Apr-12 4:17am    
no still i m not getting the answer!!!
what path to be set
Nelek 15-Apr-12 6:19am    
Not an solution... but an advice. If you don't want to get ignored, be patient. People here come in the spare time and help for free. Please respect that.

1 solution

It's difficult to be sure, but it looks like it's a path problem:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Winter.jpg
Looks like you have hard-coded a folder that doesn't exist on your web server - it is unlikely that VS will be installed there. Check where you set that, and change it to a better, relative path.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900