[CLOSED] FileUploadField doesn't work as should

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] FileUploadField doesn't work as should

    Hi,

    what I tryed to do today was upload file to my server path. fuFileUpload is a
    <ext:FileUploadField runat="server" ID="fuFileUpload"/>
    I did this in my saving logic:
                    byte[] buffer = new byte[fuFileUpload.PostedFile.ContentLength;];
                    fuFileUpload.PostedFile.InputStream.Read(buffer, 0, simpleFile.Data.FileSizeBytes);
                    //after Read operation array buffer is like a new object got every time only 0 values of all positions
    after 3hours of trying this things worked i simply changed to
    <asp:FileUpload runat="server" ID="fuFileUpload"/>
    and its worked with asp.net control like a dream.

    It's seems to be a bug. Please let me know if it's work with above example and what should I changed to make this work with ext.net.FileUploadField.

    Thanks,
    ViDom
    Last edited by Daniil; Jul 19, 2012 at 3:41 PM. Reason: [CLOSED]
  2. #2
  3. #3
    Quote Originally Posted by Daniil View Post
    Danii thats work.
    but why this read method doesn't work and why there is no examples on your page example which will show this functionality?

    Without this examples of such a funcionality it's really hard to know why things like this one doesn't work:(

    Thanks
  4. #4
    Quote Originally Posted by ViDom View Post
    but why this read method doesn't work
    I think it should work. Please provide more details. Is the FileUploadField within the <form>?
    <form runat="server">
    Quote Originally Posted by ViDom View Post
    why there is no examples on your page example which will show this functionality?
    Well, we have such example.
    https://examples1.ext.net/#/Form/FileUploadField/Basic/

    A file is uploaded in the "Form Example" at the bottom.
  5. #5
    Yeah Danii FileUploadField is in
    <form runat="server">
    also got
    <ext:ResourceManager runat="server"/>

    This example which you provide got no code for saving files with it. Have only some code of uploading which i assumed do nothing. I suggest to make more detail examples there. Display isn't such important than functionality i gues ;)
  6. #6
    Well, the server functionality is the same as it is with <asp:FileUpload> :)
  7. #7
    In my case if it's got same functionality than <asp:FileUpload> control it should work but it isn't :P

    Your solution works for me so I'm greatfull for this :)

    Thread can be closed :)

    If you Danii will don't have anything to do pls check if this issue is only from my fault or it's a bug :)
  8. #8
    Could you provide a sample to reproduce the initial issue?
  9. #9
    Quote Originally Posted by Daniil View Post
    Could you provide a sample to reproduce the initial issue?
    sure.

    .ascx :
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SimpleFile.ascx.cs" Inherits="Details.SimpleFile" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <asp:Panel runat="server" ID="pnFileUpload" CssClass="centerPanel">
        <asp:Panel runat="server" ID="pnValidation" Visible="False">
                <ul class="errors">
                    <asp:Literal runat="server" ID="litErrors" ></asp:Literal>
                </ul>
        </asp:Panel>
        <asp:Panel runat="server" ID="pnButtons">
            <table class="fileTable">
                <tr class="buttonsFile">
                    <td>
                        <asp:Button runat="server" ID="btnSave" Text="Save" CssClass="button"/>
                    </td>
                </tr>
            </table>
            <table class="fileTable">
            <tr>
                <td>
                    <asp:MultiView runat="server" ID="mView" ActiveViewIndex="0">
                        <asp:View runat="server" ID="vEdit">
                                <p>
                                    <span><ext:FileUploadField ID="fuFileUpload" FieldLabel="File"  runat="server" Width="250" Height="24" /></span>
                                </p>
                                
                                
                        </asp:View>
                        <%-- here is another View --%>
                    </asp:MultiView>
                </td>
            </tr>
        </table>
        </asp:Panel>    
    </asp:Panel>
    ascx.cs:
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    namespace Details
    {
        public partial class SimpleFile : System.Web.UI.UserControl
        {
            private List<string> Errors { get; set; }
            
    
            protected void Page_Init(object sender, EventArgs e)
            {
                btnSave.Click += new EventHandler(btnSave_Click);
            }
            
            protected void Page_Load(object sender, EventArgs e)
            {
                
            }
    
            protected void Page_PreRender(object sender, EventArgs e)
            {
                
            }
    
            protected void btnSave_Click(object sender, EventArgs e)
            {           
                    if (Save())
                    {
                        //do some redirect
                    }
            }
            private bool Save()
            {
                string path = string.Empty;
                try
                {
                    byte[] buffer = new byte[fuFileUpload.PostedFile.ContentLength]; 
                    fuFileUpload.PostedFile.InputStream.Read(buffer, 0, fuFileUpload.PostedFile.ContentLength); //after this line buffer got wrong values
                    path = @"files\";//here put ur test folder
                    SaveToFile(path,buffer);                
                }
                catch (Exception exc)
                {
                    File.Delete(path);
                    Errors.Add("<li>Save error</li></br>");                
                }
                if (Errors.Any())
                {
                    foreach (var s in Errors)
                    {
                        litErrors.Text += s;
                    }
                }
                return Errors.Count == 0;
            }
    
            protected void SaveToFile(string path,byte[] fileData)
            {
                try
                {
                    FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                    
                    BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream);
                    binaryWriter.Write(fileData);
                    binaryWriter.Flush();
                    binaryWriter.Close();
                    fileStream.Close();
                }
                catch (IOException exc)
                {
                }
            }
        }
    }
  10. #10
    Thanks, but, unfortunately, I can't launch that control getting the error:
    Compiler Error Message: CS0103: The name 'btnSave' does not exist in the current context
    
    btnSave.Click += new EventHandler(btnSave_Click);
Page 1 of 3 123 LastLast

Similar Threads

  1. Northwind example doesn't work in IE9
    By Const in forum 1.x Help
    Replies: 10
    Last Post: Dec 09, 2011, 3:04 AM
  2. Replies: 7
    Last Post: Oct 14, 2011, 9:59 AM
  3. Replies: 7
    Last Post: Mar 28, 2011, 4:51 PM
  4. FileUploadField can't work
    By Fresh.Killer in forum 1.x Help
    Replies: 1
    Last Post: Dec 07, 2009, 8:26 AM
  5. Keymap doesn't work
    By Kamal in forum 1.x Help
    Replies: 2
    Last Post: Aug 13, 2009, 10:49 AM

Tags for this Thread

Posting Permissions