hi everyone
how can i save a folder path in the sql server database and retrive it again by using vb.net 2010?
hi everyone
how can i save a folder path in the sql server database and retrive it again by using vb.net 2010?
A few clarifications and a compact how-to based on the thread: as and noted, a folder path is just a string — the important differences are how that string is obtained and what it represents (a local client folder, a server folder, or a network/UNC share). The replies so far did not distinguish desktop vs web scenarios; that distinction determines the correct UI control and what can actually be opened later.
For a VB.NET 2010 desktop (WinForms) app: present a folder picker (use FolderBrowserDialog or a modern file-picker wrapper) to capture SelectedPath, validate with IO.Directory.Exists, normalize (trim any trailing "\"), then save with a parameterized SQL command into an NVARCHAR column. To open the saved folder from the app, launch Explorer. Example snippets:
Dim dlg As New FolderBrowserDialog()
If dlg.ShowDialog() = DialogResult.OK Then
Dim folderPath As String = dlg.SelectedPath.TrimEnd("\"c)
If IO.Directory.Exists(folderPath) Then
' save folderPath to DB using parameterized INSERT/UPDATE
End If
End If ' open stored folder
Process.Start("explorer.exe", folderPath) Note: mentioned OpenFileDialog — that is for files. For folder selection use FolderBrowserDialog (or CommonOpenFileDialog from the Windows API Code Pack for a richer UI).
For ASP.NET / web apps: a web page cannot directly open a folder on a remote client's disk. If the stored path is a server-side path, expose it via a virtual directory or an endpoint that returns a file listing or a zip for download. For intranet/UNC scenarios, browsers commonly block file:// links; instead implement server-side code that reads the share (with appropriate credentials) and serves content over HTTP.
Database and safety notes: use NVARCHAR to support Unicode names; choose a length that fits expected paths (NVARCHAR(260) for traditional MAX_PATH, or NVARCHAR(512)/NVARCHAR(MAX) to avoid truncation). Always validate the path before use, store a display name/host flag if helpful, and use parameterized SQL to avoid injection and accidental command execution.
Jump to Post— JamesCherrill 4,733The URL for a folder is just like the URL for a file except that it doesn't have a file name - it just finishes with the folder name (and its final /). Either way iot's just a string that you can save in a database like any other string.
Jump to Post— JamesCherrill 4,733Please decide what question you are asking, then maybe someone will be able to give the answer. Your latest post is nothing like the original "save a folder path in the sql server database and retrive it again". In every post you change the question.
So, you are still not …
Question is not understandable.
Please, describe it perfectly and post your work what you did & what have you want.
thank you for your quick respond
i want to save the url of the folder in sql server database, so in my program when i click on the folder name take me directly to that folder.
my problem is how to save the url of the folder
i search alot in the internet all the answers is about how to save the url of the file like image, doc, text ect.... but not the url of the folder
The URL for a folder is just like the URL for a file except that it doesn't have a file name - it just finishes with the folder name (and its final /). Either way iot's just a string that you can save in a database like any other string.
Agreed with JamesCherrill, you can save file or folder path in a table as like you save a string value.
thank you for your answer
i know that the URL for a folder is just like the URL for a file, but i want my program when i click on the folder the program will take the url of the folder.
Please decide what question you are asking, then maybe someone will be able to give the answer. Your latest post is nothing like the original "save a folder path in the sql server database and retrive it again". In every post you change the question.
So, you are still not giving enough info. "when i click on the folder the program will take the url of the folder" click on it where? On the desktop, in a list box, on a web page??? "take" it in what sense?
Please take the time to describle fully what you are trying to do, in what context, and exactly what it is you don't know how to do.
Depend if you desktop app you will use control like openfiledialog to retrieve physical path
If you use asp.net you will upload control to get it after that insert in db with column have varchar datatype
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.