How to Get Full Path of FileUploadField by JAVASCRIPT or listerner

  1. #1

    How to Get Full Path of FileUploadField by JAVASCRIPT or listerner

    Hi All,

    I have a FileUploadField inside a GridPanel.
    I want to get the full name from javascript or using listeners or AjaxMethod.

    Its working fine in IE 7 i am getting the full Path by using the code, but not getting full path name in Mozilla or google chrome using the code below , there " (#{fileAttachment}.getValue())" give me the full path name in IE but not in mozilla or chrome..

    I mean if in IE its give me the path like.. "C:\\UploadedFile\Files\MyuploadFile.jpg"
    but in Mozilla or chrome its give me only " MyuploadFile.jpg".

    My FileUploadField is inside the Gridpanel , so i donot know how to use .. "fileAttachment.FileName" or "fileAttachment.PostedFile.FileName".
       <ext:Column DataIndex="FILENAME" Header="Add Attachment" Width="140px">
    
                                        <Editor>
    
                            <ext:FileUploadField runat="server" ID="fileAttachment"  ButtonOnly="true" ButtonText="Add File"
    
                                AllowBlank="true">
    
                                <Listeners>
    
                                    <FileSelected Handler="#{AjaxMethods}.GetFileName(#{fileAttachment}.getValue());" />
    
                                   
    
                                </Listeners>
    
                            </ext:FileUploadField>
    
                        </Editor>
    
                    </ext:Column>
    
    [AjaxMethod]
    public void GetFileName(string strValue)
            {
               // its work in IE but not work in Mozilla.
                int _intIndex = strValue.LastIndexOf('\\');
                string strFileName = strValue.Substring(_intIndex+1);
            }
    Can you please help me to get the full file path (like C:\\UploadedFile\Files\MyuploadFile.jpg instead of just "MyuploadFile.jpg) on client side.


    Thanks and Regards
    Kunal Mehata.
    India
    919971261098




  2. #2

    RE: How to Get Full Path of FileUploadField by JAVASCRIPT or listerner

    Hi,

    It is impossible due security reason, all modern browsers doesn't provide path (file name only)
  3. #3

    RE: How to Get Full Path of FileUploadField by JAVASCRIPT or listerner

    Hi Vladsch,

    Is there any way to get the FileUploadField assigned file in server side, where FileUploadField is INSIDE A GRIDPANEL.
    like ..
     public void GetFileName(string strValue)
            {
                int _intIndex = strValue.LastIndexOf('\\');
                string strFileName = strValue;
                if (_intIndex > 0)
                {
                    strFileName = strFileName.Substring(_intIndex + 1);
                }
                if (!string.IsNullOrEmpty(fileAttachment.FileName))
                 {
                        fileAttachment.PostedFile.SaveAs(Server.MapPath("TEMPFILE\\" + strFileName));
                 }
          }
  4. #4

    same problem~~~

    same problem~~~
    have u resolved?
  5. #5
    Hi,

    Please use the Page's MapPath method.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void FileSelected(object sender, DirectEventArgs e)
        {
            string fileName = this.FileUploadField1.FileName,
                   filePath = MapPath(fileName);
            X.Msg.Alert("FileSelected", filePath).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:FileUploadField ID="FileUploadField1" runat="server" Width="200">
                <DirectEvents>
                    <FileSelected OnEvent="FileSelected" />
                </DirectEvents>
            </ext:FileUploadField>
        </form>
    </body>
    </html>
  6. #6
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    <script type="text/javascript">
        function GetFullPath() 
        {
            Ext.getCmp('txt_file').setValue(Ext.getCmp('txt_file').fileInput.dom.value);
        }
    </script>
    </head>
    <body>
        <form id="form1" runat="server" enctype="multipart/form-data">
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <p></p><p></p>&nbsp;
        <ext:FileUploadField ID="txt_file" runat="server" Width="450" Height="26" Cls="txt_fontcolorred" ButtonText="选择文件" Icon="Attach">
            <Listeners>
                <FileSelected Fn="GetFullPath" />
            </Listeners>
        </ext:FileUploadField>
        </form>
    </body>
    </html>
    Click image for larger version. 

Name:	show_fullpath.PNG 
Views:	319 
Size:	51.1 KB 
ID:	25272

Similar Threads

  1. Replies: 1
    Last Post: Jun 04, 2012, 2:34 PM
  2. Replies: 1
    Last Post: Jan 25, 2012, 8:17 AM
  3. Replies: 6
    Last Post: Jan 11, 2012, 9:52 AM
  4. Replies: 0
    Last Post: Dec 19, 2011, 8:23 PM
  5. Get full path of selected TreeNode?
    By dbassett74 in forum 1.x Help
    Replies: 2
    Last Post: May 18, 2009, 12:40 PM

Posting Permissions