locked
Save Link as does not work for Microsoft Edge or Chrome, but Save Target as, works for IE RRS feed

  • Question

  • User-390872747 posted

    Hi,I have developed an asp.net web application, coded using C#. In one of the web pages, I create links to .CSV data files, using the Code shown below. I want the users of this web page to be able to save the .CSV data files. And they can do that successfully, as long as they use Internet Explorer. Using Internet Explorer, they do a Right Mouse Click on the link, then they select the "Save Target as" option, to save the .CSV file in their desired locations.

    So far so good. But the problem is, that this code only works when using the Internet Explorer. It does not work when using Chrome Browser or  Microsoft Edge.My understanding is that for Chrome and Microsoft Edge, using the "Save Link as" option, on right clicking the link, should work.But when the user selects Save Link as, nothing happens.

    Can you please tell me how I need to modify the code so that we can save the files using Chrome or Microsoft Edge as well ?

    		HyperLink Filelink = new HyperLink();
                    Filelink.NavigateUrl = @"\\<server name>\<folder name>\<sub folder name>\" + "Data\\"  + "my_data_filename.csv";
                    Filelink.Text = "my_data_filename.csv";
    				
                    Filelink.ToolTip = "Right Mouse Click, then Save Target as..";
                    TableRow tRowHeader = new TableRow();
                    System.Web.UI.WebControls.Table Table2.Rows.Add(tRowHeader);
                    TableCell tCellHeader1 = new TableCell();
                    tRowHeader.Cells.Add(tCellHeader1);
                    tCellHeader1.Controls.Add(Filelink);

    </div>

    Tuesday, February 16, 2021 6:08 AM

Answers

  • User-939850651 posted

    Hi Diana4,

    I think my previous statement was not clear enough, which caused you confusion.

    If the link is valid, you can save it as. A few examples (url Exact value):

    1.  

    Files under the local server. So I just need to set the url attribute like this: 

    Filelink.NavigateUrl = @"Data\my_data_filename.csv";

    In this case, you could click the hyperlink to download the file, or choose to save the link as, it can work in differenet broswes.

    2. I obtained file download links (valid and accessible) from some sharing sites for testing purposes. 

    Filelink.NavigateUrl = @"https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv";

    In this case, you could click the hyperlink to download the file, or choose to save the link as, it can work in differenet broswes.

    3. Use invalid url attribute.

    Filelink.NavigateUrl = @"\\<server name>\<folder name>\<sub folder name>\" + "Data\\"  + "my_data_filename.csv";

    In this case, the problem you mentioned will occur. When you click on the hyperlink, you cannot download the file (because the link to the address is invalid), and the error message will be prompted in the broswer console. You cannot save the link as too.

    In Edge, it will prompt you that the file cannot be downloaded, and you cannot save it as. Something like this:

    In IE, if you want to save as the link, it cannot be achieved. Although you can choose the path, when you click Save, the same prompt message as Edge will appear.

    Hope you can understand.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 18, 2021 8:23 AM

All replies

  • User-939850651 posted

    Hi Diana4,

    For a correct hyperlink, it should be allowed to be saved as, so I am not sure how do you test.

    Filelink.NavigateUrl = @"\\<server name>\<folder name>\<sub folder name>\" + "Data\\"  + "my_data_filename.csv";

    Is the attribute using an accurate value or the value you provided?

    For the test I created under the local server path, when you hover the mouse over the hyperlink, the corresponding address will appear. It should be an accessible path starting with https.

    So I think your problem may be caused by not providing a valid url attribute in HyperLink control.

    Best regards,

    Xudong Peng

    Wednesday, February 17, 2021 7:47 AM
  • User-390872747 posted

    Hello, thank you for responding. Are you saying that my file path itself is not correct ? When I use IE, I am able to save the document using right click and then "save target as"..., but when I use Edge or Chrome, there is no option to "save target as" instead there is an right click option to "save link as". The "save target as " works, but the "save link as" does not

    Can you please give me some reference where I can do some further reading to understand the issue ?

    Wednesday, February 17, 2021 3:59 PM
  • User-939850651 posted

    Hi Diana4,

    I think my previous statement was not clear enough, which caused you confusion.

    If the link is valid, you can save it as. A few examples (url Exact value):

    1.  

    Files under the local server. So I just need to set the url attribute like this: 

    Filelink.NavigateUrl = @"Data\my_data_filename.csv";

    In this case, you could click the hyperlink to download the file, or choose to save the link as, it can work in differenet broswes.

    2. I obtained file download links (valid and accessible) from some sharing sites for testing purposes. 

    Filelink.NavigateUrl = @"https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv";

    In this case, you could click the hyperlink to download the file, or choose to save the link as, it can work in differenet broswes.

    3. Use invalid url attribute.

    Filelink.NavigateUrl = @"\\<server name>\<folder name>\<sub folder name>\" + "Data\\"  + "my_data_filename.csv";

    In this case, the problem you mentioned will occur. When you click on the hyperlink, you cannot download the file (because the link to the address is invalid), and the error message will be prompted in the broswer console. You cannot save the link as too.

    In Edge, it will prompt you that the file cannot be downloaded, and you cannot save it as. Something like this:

    In IE, if you want to save as the link, it cannot be achieved. Although you can choose the path, when you click Save, the same prompt message as Edge will appear.

    Hope you can understand.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 18, 2021 8:23 AM
  • User-390872747 posted

    Hi, Thank you for your response. I am able to get the "Save Link as.." to work now, in Edge and Chrome, if I write the code as indicated in option number 2 of your response. It opens up the "Save As" dialog box, allowing me to save my_data_filename.csv in a windows explorer folder of my choice. That is great.

    There is one problem however. After I select "Save Link as...", it takes a good 20 seconds or so, to open up the "Save As" dialog box. In that 20 seconds, I get no indication, from the browser that it is working, that I should wait for few seconds, and it will soon give me the "Save As" dialog box. Is there a way to enable some kind of timer which can give such an indication ? Thank you  

    Filelink.NavigateUrl= @"https://<server name>/<folder name>/<sub folder name>/my_data_filename.csv"
    Friday, February 19, 2021 12:32 PM
  • User-939850651 posted

    Hi Diana4,

    There is one problem however. After I select "Save Link as...", it takes a good 20 seconds or so, to open up the "Save As" dialog box. In that 20 seconds, I get no indication, from the browser that it is working, that I should wait for few seconds, and it will soon give me the "Save As" dialog box.

    For this problem, I did some searches on it and found this problem can happen because of Windows 10 and a network path that is no longer available but "Quick Access" is trying to read the location and timed out.

    To fix this issue, go to my computer (file explorer), Right click on Quick Access > Options

    Uncheck both options under "Privacy" then click clear

    This is the related article:

    https://support.google.com/chrome/thread/10347775?hl=en

    Best regards,

    Xudong Peng

    Tuesday, February 23, 2021 8:19 AM