0

I need to convert files like pdf and word into links. Is it possible to convert files into attachments? If I click on the link, the file should be downloaded. I tried the below code for getting a link. But it could be opened on our computer only and not opened on another computer because that computer does not have this pdf. Then how to convert the file to a link using c#.

var urlFile = new System.Uri(@"D:\ImagePdf.pdf");
var linkPath = urlFile.AbsoluteUri;

linkPath output is file:///D:/ImagePdf.pdf

  • 4
    To be accessed by another PC the file should be inside a shared folder or a server disk... if it's on a shared folder on the PC the link could be `\\PC_NAME\shared_folder_name\file_name.pdf` ... this has nothing to do with C# – Marco Beninca Sep 09 '22 at 10:10
  • Other computers have access to this file through UNC? is it a web or a windows application? – Mahdi Farhani Sep 09 '22 at 10:11
  • I am using the windows application. Can you kindly give me any suggestion for this query – Karmegam S Sep 09 '22 at 10:17
  • 2
    Even if you used UNC path, there is no guarantee that the users can be able to download such a unc path based file, because it depends on the access permissions for that user on that "shared folder". Your question needs to be revisited, if you want to provide the file to any of the other users of your application, then you need to store that in a central place - either file system or blob in db table or in some cloud service like s3 or Azure blob storage - it depends on your application use case. – Anand Sowmithiran Sep 09 '22 at 10:27

2 Answers2

0

First create a share folder and ensure other computers have access to this folder.

Second specified your computer name/IP address as a setting in your application.

Finally your link could be like this \\{Computer Name\IP address}{Your Share foldername}{Your filename + extension}

Mahdi Farhani
  • 964
  • 1
  • 9
  • 22
-1

You can use System.Diagnostic.Process.Start("filePath") to open the file and you can use System.IO.FIle.Copy() method to "Download" the file. The file must be inside a shared folder to be accessed.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
S. Stefano
  • 34
  • 9