Monday, 29 February 2016

HTML Text To Excel Export

 Response.AppendHeader("content-disposition", "attachment;filename=ExportedHtml.xls");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.ms-excel";
        this.EnableViewState = false;
        Response.Write(HTMLBodyText);
        Response.End();

Saturday, 6 February 2016

Download with c# and rename file

 string strURL=txtFileName.Text;
        WebClient req=new WebClient();
        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.ClearContent();
        response.ClearHeaders();
        response.Buffer= true;
        response.AddHeader("Content-Disposition","attachment;filename=\"" + Server.MapPath(strURL) + "\"");
        byte[] data=req.DownloadData(Server.MapPath(strURL));
        response.BinaryWrite(data);
        response.End();

Friday, 5 February 2016

Copy text using javascript

<div style="position:absolute;">
        <hr />
        Test by dharmendra
        <script>

        function copyfieldvalue(e, id) {
            var field = document.getElementById(id)
            field.focus()
            field.setSelectionRange(0, field.value.length)
           // window.prompt("Copy to clipboard: Ctrl+C, Enter", field.value);
            var copysuccess = copySelectionText()
            if (copysuccess) {
                showtooltip(e)
            }
        }
        function copySelectionText() {
            var copysuccess // var to check whether execCommand successfully executed
            try {
                copysuccess = document.execCommand("copy") // run command to copy selected text to clipboard
            } catch (e) {
                copysuccess = false
            }
            return copysuccess
        }
        </script>

        <fieldset style="max-width: 600px">
            <legend>Share this tutorial</legend>
            <input id="url" type="text" size="60" value="http://www.javascriptkit.com/javatutors/copytoclipboard.shtml" />
            <a href="#" onclick="copyfieldvalue(event, 'url');return false">Copy</a>
        </fieldset>