0

We have a application hosted in some other server located in another country, I am going to use that application from different country, while using that application i want to check the user's machine local 'C' drive particular path is having that file is exist or not.

How to achieve this from C# or Javascript?

From the C#

byte[] contents = null;
if (File.Exists("C:\Program Files (x86)\Fruit\fruitList.txt"))
     {
        using (FileStream fileStream = File.OpenRead(scannedFile))
        {
               contents = new byte[fileStream.Length];
        }
     }

but that mentioned 'C' drive path is searching in IIS server only (where we hosted the application). But i want to check in client (user's) machine.

I couldn't find a code in Javascript.

Please help me, to achieve the expected result.

Thank you.

4 Answers 4

6

What you are attempting to do is not easily possible. JS will not work as it is blocked from accessing the user's client machine for security reasons. C# cannot access the client at all as it runs on the server.

The alternative is for the user to manually pick the required file from their machine using a <input type="file" /> then upload that file to your server for it to be processed and validated.

Failing that you could write a program which the user installs on their machine which provides methods for your website to retrieve information from the client - however this is an incredibly involved process.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your response, My scenario is, If the file is not exist in client's machine, I am going to ask the client to download my installer. How can i achieve this scenario, Could you please suggest on this?
Is there anything you're unclear on in my answer above?
I 'm clear on your answer, I couldn't use the <input type="file" /> for my scenario, so i' m asking you for a suggestion to achieve my scenario.
@Cegone ... most people will download a "Web installer" which then checks if the files are there, and if not then downloads them.
0

You cant access the clients drive from the server side, would be a major security issue. You will have to ask the client to tell you if they have the file or not or find another work around. This is also whys its searching in IIS server, because it thinks you are looking for a local file. Hope this helps!

Comments

0

In a Website (C#) you will only have access to the files of the server because is the machine who is executing the application.

For Javascript who is execute in the client, that's not possible because client file access is not allowed by design, read this article:

Javascript Security

If you need this you have to develop an application to install in the client's PC and connect the server from this application, this is the only way, you will never have access to the client files since the browser.

Comments

0

Use this way

C#

var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

Get the file extension from fileStream variable

Javascript:

<input id="File" type="file"/>
$("#File")[0].files[0].name.split(".")

1 Comment

You seem to have misunderstood the OPs request and the inherent flaws with it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.