Click here to Skip to main content
16,021,293 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string ftpBaseAddress = @"ftp://ftp.fsgetme.com/httpdocs/Klicksi OCR/textFiles/";
    string username = "****";
    string password = "****";

    FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(ftpBaseAddress + "/" + Path.GetFileName(FileUpload1.PostedFile.FileName));

    request.Method = WebRequestMethods.Ftp.UploadFile;
    request.Credentials = new NetworkCredential(username, password);
    request.UsePassive = true;
    request.UseBinary = true;
    request.KeepAlive = false;




    string filepath = @"ftp://ftp.fsgetme.com/httpdocs/Klicksi OCR/textFiles/" + filename;
    ViewState["fname"] = filename;
    using (Stream destination = request.GetRequestStream())
    {
        filename = FileUpload1.FileName;

        FileUpload1.PostedFile.InputStream.CopyTo(destination);

        destination.Flush();
    }


    Image1.ImageUrl = "";
    Image1.ImageUrl = "~/Klicksi OCR/textFiles/" + filename;


    Label1.Text = SaveUpload(FileUpload1);
    Boolean FileOK = false;
    Boolean FileSaved = false;

    if (FileUpload1.HasFile)
    {

        Session["WorkingImage"] = FileUpload1.FileName;
        String FileExtension = Path.GetExtension(Session["WorkingImage"].ToString()).ToLower();
        String[] allowedExtensions = { ".png", ".jpeg", ".jpg", ".gif", ".tif",".tiff",".bmp"};


        for (int i = 0; i < allowedExtensions.Length; i++)
        {
            if (FileExtension == allowedExtensions[i])
            {
                FileOK = true;

            }
        }


    }



    if (FileOK)
    {
        try
        {


            FileUpload1.PostedFile.SaveAs(path + Session["WorkingImage"]);
            FileSaved = true;
        }
        catch (Exception ex)
        {
            lblError.Text = "File could not be uploaded." + ex.Message.ToString();
            lblError.Visible = true;
            FileSaved = false;
        }
    }
    else
    {




        lblError.Text = "Cannot accept files of this type.";
        lblError.Visible = true;
    }

    if (FileSaved)
    {
        //pnlUpload.Visible = false;
        pnlCrop.Visible = true;
        Image1.ImageUrl = "images/" + Session["WorkingImage"].ToString();
    }
}
private string SaveUpload(FileUpload fl)
{
    if (fl.HasFile)
    {
        try
        {
            int version = 0;
            string filename = Path.GetFileName(fl.FileName); // You may want to all an output path spec here.
            byte[] filedata = fl.FileBytes;
            File.WriteAllBytes(filename, filedata);
            return string.Format("{0} uploaded", filename);
        }
        catch (Exception ex)
        {
            return "The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }
    return "Please select a file.";
}


protected void Button4_Click(object sender, EventArgs e)
{
      filename = ViewState["filename"].ToString(); // Here gets this ERROR
        String ImagePath = Server.MapPath("~/Klicksi OCR/textFiles/" + filename);



        ReadTextFromImage(ImagePath);

        string name = Path.GetFileNameWithoutExtension(ImagePath);
        string StoreTextFilePath = Server.MapPath("~/Klicksi OCR/convertedFiles/" + name + ".txt");




        ReadTextFromImage(ImagePath, StoreTextFilePath);


}
Posted
Updated 22-Oct-13 22:31pm
v2
Comments
OriginalGriff 23-Oct-13 4:26am    
Any particular line, or should we just guess?
CPallini 23-Oct-13 4:26am    
You should post the exact error message (it provides, for instance, the line number where it occurred).
Sampath Lokuge 23-Oct-13 4:28am    
Put a brake point and check the exact location from where is it coming. Then put that code snippet here,If you need a solution.

1 solution

Perhaps, if you used the same name for indexes, it would work a little better?
C#
      ViewState["fname"] = filename;
...
      filename = ViewState["filename"].ToString(); // Here gets this ERROR
Either "fname" or "filename" should fix it, but not both! :laugh:
 
Share this answer
 
Comments
thatraja 23-Oct-13 5:36am    
:D 5!

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