简体   繁体   中英

How to Make show Save As Dialog box in asp.net web Application using Button click

I have worked in Web Application exporting datas in grid and I want to Save them Using Save as dialog box either in C#,Javascript.

function openDialog() {

        var input = $(document.createElement('input'));
        input.attr("type", "file")
        input.trigger('click');
        return false;
    }

test

    [HttpGet]
    public async Task<HttpResponseMessage> Get(string fileHash)
    {
        //read file 
        byte[] fileData = await _deviceFileApiService.GetFileData(fileHash);

        HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(fileData)
        };
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = fileResource.FileName
        };

        return response;
    }

on UI

<a href="<you url to action here>/get">save as</a>

When user click on link, save as dialog will be appeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM