Wednesday 11 June 2014

Show an Alert Message if no file was uploaded in RadfileExplorer Upload Popup

We may have scenario like to validate if no file was uploaded in Rad upload of rad file explorer
For this first write an javascript function like this in design page:
function OnClientLoad(explorer, args) {
//Find upload button and attach an event handler
                var uploadButton = $find("<%=RadFileExplorer1.ClientID%>" +"_btnUpload");
                uploadButton.add_clicked(function()
                {
                    var upload = $find('<%=RadFileExplorer1.Upload.ClientID %>');
                    var inputs = upload.getFileInputs();
                    var count = 0;
                    for (var i = 0 ; i < inputs.length; i++) {
                        if (inputs[i].value.length != 0) {
                            count++;
                        }
                    }
                    if(count == 0)
                        alert('Please select one file to upload.');
                })
            }
And add this function in RadfileExplorer client load event like

<telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" OnClientLoad="OnClientLoad"  </telerik:RadFileExplorer>

Monday 9 June 2014

Partial Page Refresh after Download of file or using of Response.end in aspx page using iframe

Initially Declare a generic Handler like this
    public class Handler1 : IHttpHandler
    {

        #region IHttpHandler Members

        private HttpContext _context;
        private HttpContext Context
        {
            get
            {
                return _context;
            }
            set
            {
                _context = value;
            }
        }


        public void ProcessRequest(HttpContext context)
        {
            Context = context;
            string filePath = context.Request.QueryString["path"];
            filePath = context.Server.MapPath(filePath);

            if (filePath == null)
            {
                return;
            }

            System.IO.StreamReader streamReader = new System.IO.StreamReader(filePath);
            System.IO.BinaryReader br = new System.IO.BinaryReader(streamReader.BaseStream);

            byte[] bytes = new byte[streamReader.BaseStream.Length];

            br.Read(bytes, 0, (int)streamReader.BaseStream.Length);

            if (bytes == null)
            {
                return;
            }

            streamReader.Close();
            br.Close();
            string extension = System.IO.Path.GetExtension(filePath);
            string fileName = System.IO.Path.GetFileName(filePath);
            WriteFile(bytes, fileName, "application/" + extension, context.Response);
        }

        /// <summary>
        /// Sends a byte array to the client
        /// </summary>
        /// <param name="content">binary file content</param>
        /// <param name="fileName">the filename to be sent to the client</param>
        /// <param name="contentType">the file content type</param>
        private void WriteFile(byte[] content, string fileName, string contentType, HttpResponse response)
        {
            response.Buffer = true;
            response.Clear();
            response.ContentType = contentType;
            response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            response.BinaryWrite(content);
            response.Flush();
            response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        #endregion
    }
}

Next declare an iframe in aspx page (design)
<iframe id="iframe1 " style="display: none" runat="server" ></iframe>
and an update panel
<asp:UpdatePanel ID="UpdatePanel1 " runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
//controls design goes here
//Lets assusme we have a GridView1 here
</ContentTemplate>
</asp:UpdatePanel>
Next in aspx codebehind file write code as follows:
Some EventHandler()
{
//Method to bind GridView1 data
UpdatePanel1.Update();
   string path="Handler1.ashx?path=" + "declare your path here";
    iframe1.Attributes["src"] = path;
}
We are done:
Now we can see the page is partially refreshed when we called that event.




Wednesday 4 June 2014

Disable the text in Rad FileExplore Upload Popup

To disable the text in Rad FileExplore Upload Popup
Add the following Property in  onclientLoad = "OnClientLoad" on rad file explorer Property on design file
Next Add following java script :
function OnClientLoad (explorer, args) {
                $telerik.$(".ruFakeInput").attr("disabled", "disabled");
}
But this will disable the initial items only so if client clicks on Add button we need to disable them also
So add following java script like
function OnClientAdded(upload, args) {
                $telerik.$(".ruFakeInput").attr("disabled", "disabled");
            }

Next Add line like RadFileExplorer1.Upload.OnClientAdded = "OnClientAdded"; in Page load event of code behing file
We are done and disabled the text entering in Rad FileExplorer Upload Popup.