1

I want to get path of the folder so that i need to post the path of the selected folder to the backend so it receives like this

string path2 = Path.GetDirectoryName(@"C:\Users\Public\Desktop\workspace\");

I tried <input directory="" webkitdirectory="" type="file" />it doesn't show the path of the folder it just shows like foldername/filename.jpg i want the path like C:\Users\Public\Desktop\workspace\ kindly guide me how to do that.

3 Answers 3

0

You cannot do so - the browser will not allow this because of security concerns.

When a file is selected by using the input type=file object, the value of the value property depends on the value of the "Include local directory path when uploading files to a server" security setting for the security zone used to display the Web page containing the input object.

The fully qualified filename of the selected file is returned only when this setting is enabled. When the setting is disabled, Internet Explorer 8 replaces the local drive and directory path with the string C:\fakepath\ in order to prevent inappropriate information disclosure.

See https://webplatform.github.io/docs/html/elements/input/type/file/ for more info about this.

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

Comments

0

You cannot do that in React, if you still want to get the file path I would suggest you doing Electron and use fs inside the Electron.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-1

in react js I just want to know the filenames so i just simply use the file target function

import React, { useState } from "react";

export default function App() {
const [filename, setFileName] = useState([]);

const handle = (event) => {
const data = [];
for (let i = 0; i < event.target.files.length; i++) {
  data.push(event.target.files[i]);
}

console.log("data :- ", data);
setFileName(data);
};

return (
<div className="App">
  <h1>Hello...</h1>

  <input type="file" onChange={handle} multiple />

  <table class="table">
    <thead>
      <tr>
        <th scope="col">#</th>
        <th scope="col">File name</th>
      </tr>
    </thead>
    {fileName.map((item, i) => {
      return (
        <React.Fragment key={i}>
          <tbody>
            <tr>
              <th scope="row">{i}</th>
              <td>{item.name}</td>
            </tr>
          </tbody>
        </React.Fragment>
      );
    })}
  </table>
</div>
);
}

Comments

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.