Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to Show/Download the Shared file, but I am not getting results. For these I have tried below code.

Shared folder path: \\192.168.10.144 (Which is another IP with in the network).

Any solution please?

What I have tried:

C#
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        try
        {
            var linkBtn = sender as LinkButton;

            string[] fileNames = linkBtn.Text.Split('\\');
            //string tempfile = linkBtn.Text.Replace('\\', '/');
            string tempFileName = fileNames[fileNames.Length - 1];

            /*Response.ContentType = "image/jpeg";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + tempFileName);
            Response.TransmitFile(linkBtn.Text);
            Response.End();*/

            Response.Buffer = true;
            Response.Clear();
            Response.AppendHeader("Content-Type", "application/jpg");
            Response.AppendHeader("Content-disposition", "attachment; filename=" + tempFileName + ".pdf");
            FileStream sourceFile = new FileStream(linkBtn.Text, FileMode.Open);
            long FileSize;
            FileSize = sourceFile.Length;
            byte[] getContent = new byte[(int)FileSize];
            sourceFile.Read(getContent, 0, (int)sourceFile.Length);
            sourceFile.Close();
            Response.BinaryWrite(getContent);
            Response.Flush();
            Response.Close();

        }
        catch (SoapException sx)
        {
            msg = sx.Message.Replace("'", "");
            msg = msg.Replace("\n", "");
            lblErrorMessage.Text = msg;
        }
        catch (Exception ex)
        {
            msg = ex.Message.Replace("'", "");
            msg = msg.Replace("\n", "");
            lblErrorMessage.Text = msg;
        }
    }
Posted
Comments
F-ES Sitecore 12-Jun-18 7:17am    
By default the account your asp.net code runs under doesn't have access to the network so can't read files from a share. You'll need to change the account your code runs under to an account that has the relevant access.
Bojjaiah 12-Jun-18 7:24am    
shared path(have full permission) will access everyone.
F-ES Sitecore 12-Jun-18 7:26am    
The account has no access to the network so the permissions on the share are irrelevant.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900