none
Search and open pdf documents that are inside a folder using silverlight, C# RRS feed

  • Question

  • I need to find a way to search and display pdf documents of a specific route, I have the following code where I show the route and its folder (transfer.IdTransfer)

    System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("_sl_historyFrame");
                if (myFrame != null)
                {
                    myFrame.SetStyleAttribute("width", "1024");
                    myFrame.SetStyleAttribute("height", "768");
                    Uri uri = new Uri(@"\\192.168.1.216\UploadFileMobilePDF\" + transfer.IdTransfer);
                    string path = uri.AbsoluteUri.ToString();
                    myFrame.SetAttribute("src", path);
                    myFrame.SetStyleAttribute("left", "0");
                    myFrame.SetStyleAttribute("top", "50");
                    myFrame.SetStyleAttribute("visibility", "visible");
                }

    I have tried to implement a foreach cycle to search for pdf documents, but apparently silverlight does not allow it to do so as follows:

     DirectoryInfo folderPath = new DirectoryInfo(@"\\192.168.1.216\UploadFileMobilePDF\" + transfer.IdTransfer);
                if (!folderPath.Exists)
                {
                    return;
                }
                foreach (var file in folderPath.EnumerateFiles("*.pdf", SearchOption.AllDirectories))
                {
                    System.Diagnostics.Process.Start(file.FullName);
                    //Uri uri = new Uri(folderPath + file.FullName);
                }
    I want to know the correct way to search and display pdf documents using silverlight, please


    Edgar Rojas H.

    Monday, September 9, 2019 2:48 PM

All replies

  • Silverlight cannot access arbitrary files on the client file system.  Apps in a browser run in a "sandbox" that protects the system against malicious code.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, September 9, 2019 6:09 PM
  • Silverlight cannot access arbitrary files on the client file system.  Apps in a browser run in a "sandbox" that protects the system against malicious code.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.


    So there is no way to open documents using silverlight?

    Edgar Rojas H.

    Monday, September 9, 2019 6:14 PM
  • No.  You cannot access any files on the user's computer from inside a browser.  That's for security reasons.  You can't allow arbitrary Javascript code to read your local files, and Silverlight runs in exactly the same environment as Javascript.

    As was mentioned in your other thread. if these files are on a file server that can also be accessed by your web server, you can do the job on your web server.  You would need to create a handler on your web server that accepts a file name and returns the file from the file server.  Then, your Silverlight code could convert the file name into an HTTP request. 


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, September 10, 2019 6:30 AM
  • No.  You cannot access any files on the user's computer from inside a browser.  That's for security reasons.  You can't allow arbitrary Javascript code to read your local files, and Silverlight runs in exactly the same environment as Javascript.

    As was mentioned in your other thread. if these files are on a file server that can also be accessed by your web server, you can do the job on your web server.  You would need to create a handler on your web server that accepts a file name and returns the file from the file server.  Then, your Silverlight code could convert the file name into an HTTP request. 


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    I need to use HttpClient() for convert the file name into an HTTP request.?

    Edgar Rojas H.

    Tuesday, September 10, 2019 1:35 PM