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); }
ViewState["fname"] = filename; ... filename = ViewState["filename"].ToString(); // Here gets this ERROR
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)