when entering a value, it should show me a window with tree view of my local directories.
when I select a directory, I need to show only the full path in my text box.
So i need to show the path of the selected folder from my local folders. How can I do this ?
Any help or suggestions please ?
This is a support forum. The idea is you design and write code to meet your requirements. If you run into trouble then share your code. Explain how the code is intended to work and how the code actually works.
At this point you are asking the community design and write your code. It also seems this question might be related to a Telerik control. You should post this question on Telerik's support forum for help using the paid for framework.
If it’s the local folder on the client machine and not the server, this capability does not exist. More secure browsers won’t even give the path to a selected file in the file control.
so can I do this in the server side ? it's possible ? if yes ..how can i implement it ?
You have not provided enough information or code to understand what you are trying to do. If you are trying to read the files in the client machine, then no, reading client files is not possible form a web server.
If all you want to do is get a directory listing from the server then see the Syustem.IO namespace.
public async Task<ActionResult> Poste_Add(PosteModel model)
{
using (var client = new HttpClient(new LoggingHandler(new HttpClientHandler())))
client.BaseAddress = new Uri(AppSetting.AppPath);
var result = await client.PostAsJsonAsync("api/Postes", model);
if (result.IsSuccessStatusCode)
{
TempData["NotificationMessage"] = new NotificationModel() { Severity = "success", Title = "added !" };
return RedirectToAction("PostesList");
}
else
{
ModelState.AddModelError(string.Empty, "Server error try after some time.");
}
return View();
}
my WS works fine when adding data.
I want to add for example a button right next the backup path field.
When i chick this buttonn i need to get the browse option so that i can browse all folders in my system, after that if i select the folder, the folder path should be displayed in my TextBox like C:/Users/myFolder/ in textbox.. also when select an
UNC path and test if the folder exists in my local folders.
As explained several times, it is NOT possible to for a web server to save a file on a client machine. The client must download the file from the server.
If the server has access to a network share, then it is up to you to write code that displays location options the user can select or provide a freeform input if the user knows what to enter.
Sorry, but it seems you didn't understand my question.
this is not what i am looking for because i don't want to save a file on a client machine. I need just to get the path of
the selected folder
not file and save it as a string in my DB.
Sorry, but it seems you didn't understand my question.
this is not what i am looking for because i don't want to save a file on a client machine. I need just to get the path of
the selected folder
not file and save it as a string in my DB.
I understand the question. There is no tool that allows a browser to select a folder from a network share or a location on the web server.
It is up to you as the developer to write the UI. You can use a text input where the user can enter a folder or you can provide a list of folders the user can select. Either way it is up to you to design and write code.
Do you mean "local" to the browser side or "local" to the server side? If you want to uplaod files see for example
How to upload files to ASP.NET MVC application (aurigma.com) .If you want to show a server side tree, there is not built in control for that and you'll have to render your own.
Your exact intent could also help (what would you do with this path ?, keep in mind the web server doesn't have access to browser side files)
Edit: this is to select in which server side folder you'll uplload a client side file?
Edit 2: seems I missed your explanation. For now it seems your intent is to write content directly to a location on the browser side. It may appear to work when testing with the web server and the browser side being the same machine but a real web server
doesn't have access to client side disk for safety reason.
The usual approach for downloading a file is to trigger a download dialog in the browser using for example
FileResult Class (System.Web.Mvc) | Microsoft Docs and the user then uses this dialog to do whatever he wants with this content.
This is what i am looking for because i didn't fount the way to make the user enter a folder in the text box as you explained.
User input is covered in every beginning level MVC tutorial.
Below is a basic example that display a list of folder in a select. These folder exist on the server. I provided a link above that shows how to use the System.IO namespace to parse the file system. There is also a text input which allows the user can
select/create a sub folder if needed. Helpfully this sparks some ideas on your end.
namespace MvcBasic.Controllers
{
public class ViewModel
{
public List<SelectListItem> Options { get; set; }
[Required]
public string SelectedOption { get; set; }
public string Folder { get; set; }
}
public class BasicFormsController : Controller
{
// GET: BasicForms
[HttpGet]
public ActionResult Index()
{
ViewModel vm = new ViewModel()
{
Options = PopulateOptions()
};
return View(vm);
}
[HttpPost]
public ActionResult Index(ViewModel model)
{
ViewModel vm = new ViewModel()
{
Options = PopulateOptions(),
SelectedOption = model.SelectedOption
};
ViewBag.Message = $"You selected directory {model.SelectedOption} and folder {model.Folder}";
return View(vm);
}
private List<SelectListItem> PopulateOptions()
{
string[] dirs = Directory.GetDirectories(@"c:\Projects", "*", SearchOption.TopDirectoryOnly);
List<SelectListItem> options = new List<SelectListItem>();
foreach (string dir in dirs)
{
options.Add(new SelectListItem()
{
Text = dir,
Value = dir
});
}
return options;
}
}
}
Sorry, but it seems you didn't understand my question.
this is not what i am looking for because i don't want to save a file on a client machine. I need just to get the path of
the selected folder
not file and save it as a string in my DB.
Thank you.
you can not select a folder on the client machine. The server can do a dir of any network shares (this requires the app pool to have domain access) and display a list the user could select. See system.if for dir commands the server can do.
Member
8 Points
22 Posts
select folder from local and show the full path in my text box
Dec 21, 2020 04:50 PM|silbahi|LINK
Hello,
I am working with asp.net mvc (telerik ui)
I have a textbox named path of poste.
when entering a value, it should show me a window with tree view of my local directories.
when I select a directory, I need to show only the full path in my text box.
So i need to show the path of the selected folder from my local folders. How can I do this ?
Any help or suggestions please ?
All-Star
52091 Points
23211 Posts
Re: select folder from local and show the full path in my text box
Dec 21, 2020 04:55 PM|mgebhard|LINK
This is a support forum. The idea is you design and write code to meet your requirements. If you run into trouble then share your code. Explain how the code is intended to work and how the code actually works.
At this point you are asking the community design and write your code. It also seems this question might be related to a Telerik control. You should post this question on Telerik's support forum for help using the paid for framework.
All-Star
57844 Points
15487 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 12:43 AM|bruce (sqlwork.com)|LINK
If it’s the local folder on the client machine and not the server, this capability does not exist. More secure browsers won’t even give the path to a selected file in the file control.
Member
8 Points
22 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 01:36 PM|silbahi|LINK
so can I do this in the server side ? it's possible ? if yes ..how can i implement it ?
All-Star
52091 Points
23211 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 02:01 PM|mgebhard|LINK
You have not provided enough information or code to understand what you are trying to do. If you are trying to read the files in the client machine, then no, reading client files is not possible form a web server.
If all you want to do is get a directory listing from the server then see the Syustem.IO namespace.
https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=net-5.0
Again, share your code.
Member
8 Points
22 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 05:28 PM|silbahi|LINK
I apologize because I was not too clear.
I have a simple form with some textBox to fill:
myView.cshtml
PostesController.cs
my WS works fine when adding data.
I want to add for example a button right next the backup path field.
When i chick this buttonn i need to get the browse option so that i can browse all folders in my system, after that if i select the folder, the folder path should be displayed in my TextBox like C:/Users/myFolder/ in textbox.. also when select an UNC path and test if the folder exists in my local folders.
this is what i'm looking for.. thanks !
All-Star
52091 Points
23211 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 06:18 PM|mgebhard|LINK
As explained several times, it is NOT possible to for a web server to save a file on a client machine. The client must download the file from the server.
If the server has access to a network share, then it is up to you to write code that displays location options the user can select or provide a freeform input if the user knows what to enter.
Member
8 Points
22 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 06:32 PM|silbahi|LINK
Sorry, but it seems you didn't understand my question.
this is not what i am looking for because i don't want to save a file on a client machine. I need just to get the path of the selected folder not file and save it as a string in my DB.
Thank you.
All-Star
52091 Points
23211 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 06:45 PM|mgebhard|LINK
I understand the question. There is no tool that allows a browser to select a folder from a network share or a location on the web server.
It is up to you as the developer to write the UI. You can use a text input where the user can enter a folder or you can provide a list of folders the user can select. Either way it is up to you to design and write code.
Member
8 Points
22 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 07:05 PM|silbahi|LINK
If I had found the way to do this, I would not have asked the question to help me.
This is what i am looking for because i didn't fount the way to make the user enter a folder in the text box as you explained.
Best regards.
All-Star
48260 Points
17978 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 07:42 PM|PatriceSc|LINK
Hi,
Do you mean "local" to the browser side or "local" to the server side? If you want to uplaod files see for example How to upload files to ASP.NET MVC application (aurigma.com) .If you want to show a server side tree, there is not built in control for that and you'll have to render your own.
Your exact intent could also help (what would you do with this path ?, keep in mind the web server doesn't have access to browser side files)
Edit: this is to select in which server side folder you'll uplload a client side file?
Edit 2: seems I missed your explanation. For now it seems your intent is to write content directly to a location on the browser side. It may appear to work when testing with the web server and the browser side being the same machine but a real web server doesn't have access to client side disk for safety reason.
The usual approach for downloading a file is to trigger a download dialog in the browser using for example FileResult Class (System.Web.Mvc) | Microsoft Docs and the user then uses this dialog to do whatever he wants with this content.
All-Star
52091 Points
23211 Posts
Re: select folder from local and show the full path in my text box
Dec 22, 2020 09:33 PM|mgebhard|LINK
User input is covered in every beginning level MVC tutorial.
Below is a basic example that display a list of folder in a select. These folder exist on the server. I provided a link above that shows how to use the System.IO namespace to parse the file system. There is also a text input which allows the user can select/create a sub folder if needed. Helpfully this sparks some ideas on your end.
All-Star
57844 Points
15487 Posts
Re: select folder from local and show the full path in my text box
Dec 23, 2020 05:25 AM|bruce (sqlwork.com)|LINK
you can not select a folder on the client machine. The server can do a dir of any network shares (this requires the app pool to have domain access) and display a list the user could select. See system.if for dir commands the server can do.