Could not find a part of the path 'D:\OLMS\'

Course Queries Syllabus Queries 3 years ago

847 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

 


Protected
Sub btnadd_sylbus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadd_sylbus.Click Dim extension As String = System.IO.Path.GetExtension(FileUpload_sylbus.PostedFile.FileName).ToLower() Dim Type As String = Nothing If (extension = ".pdf") Then Dim intFileNameLength As Integer Dim strFileNamePath As String Dim strFileNameOnly As String strFileNamePath = FileUpload_sylbus.PostedFile.FileName intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\") strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2) Dim br As New BinaryReader(FileUpload_sylbus.PostedFile.InputStream) FileUpload_sylbus.PostedFile.SaveAs("D:\OLMS\" & strFileNameOnly) cmd.CommandText = "INSERT into Syllabus(sylbus_id, sylbus_name, file_name, content) values(@id,@name,@file,@cont)" cmd.Connection = cn cmd.Parameters.Add("@id", txtsylbus_id.Text) cmd.Parameters.Add("@name", txtsylbus_name.Text) cmd.Parameters.Add("@file", FileUpload_sylbus.FileName) cmd.Parameters.Add("@cont", br.ReadBytes(FileUpload_sylbus.PostedFile.ContentLength)) cmd.ExecuteNonQuery() cn.Close() lbladd_sylbus.Visible = True lbladd_sylbus.Text = "File Upload Success." txtsylbus_id.Text = Nothing txtsylbus_name.Text = Nothing Else lbladd_sylbus.Visible = True lbladd_sylbus.Text = "Not a Valid file format" End If End Sub
0 views
0 shares

profilepic.png
manpreet 3 years ago

You could try this code

strFileNamePath = FileUpload_sylbus.PostedFile.FileName
strFileNameOnly = Path.GetFilename(strFileNamePath)
Dim newFileNamePath as String = Path.Combine("D:\OLMS", strFileNameOnly)
Dim br As New BinaryReader(FileUpload_sylbus.PostedFile.InputStream)
FileUpload_sylbus.PostedFile.SaveAs(newFileNamePath)

Now, if you still get errors in accessing the folder D:\OLMS then you have this path outside the root folder of your site and your machine configuration (search about MEDIUM TRUST) disallows writing outside the root folder. (Of course I am assuming that the folder D:\OLMS exists and the user under which the IIS ASP.NET service is running has all the permissions to write in that folder)


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum