15,905,776 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by bhagawan sahay (Top 3 by date)
bhagawan sahay
9-May-15 0:14am
View
you were right here is the error:
System.UnauthorizedAccessException: Access to the path 'C:\HostingSpaces\vmtindus\vmtindustry.co.in\wwwroot\Uploads\chaff-cutter.jpeg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.UI.WebControls.FileUpload.SaveAs(String filename) at VMTAdmin_AddProduct.Button1_Click(Object sender, EventArgs e) in C:\HostingSpaces\vmtindus\vmtindustry.co.in\wwwroot\Admin\AddProduct.aspx.vb:line 24
bhagawan sahay
8-May-15 3:56am
View
here is complete code please help
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports DataOperations
Partial Class VMTAdmin_AddProduct
Inherits System.Web.UI.Page
Dim lastid As Integer
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Label9.Text = ""
lastid = GetLastId("Products")
Catch ex As Exception
End Try
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If FileUpload1.PostedFile IsNot Nothing Then
Try
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
'Save files to disk
FileUpload1.SaveAs(Server.MapPath("~/Uploads/" & FileName))
Dim result As Boolean = addDataUsingAdepter(lastid + 1, TextBox1.Text, "~/Uploads/" + FileName, TextBox2.Text, DropDownList1.Text)
If (result = True) Then
Label9.ForeColor = Drawing.Color.Green
Label9.Text = "Product Added Successfully"
TextBox1.Text = ""
TextBox2.Text = ""
DropDownList1.SelectedIndex = 0
Else
Label9.ForeColor = Drawing.Color.Red
Label9.Text = "Sorry An Error Occured"
End If
Catch ex As Exception
End Try
End If
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
DropDownList1.SelectedIndex = 0
End Sub
Public Shared Function addDataUsingAdepter(id As Integer, Name As String, photoFilePath As String, Description As String, type As String) As Boolean
Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim conn As SqlConnection
Dim adptr As SqlDataAdapter
Dim dt As String = Now.Day.ToString + "/" + Now.Month.ToString + "/" + Now.Year.ToString + " " + Now.Hour.ToString + ":" + Now.Minute.ToString + ":" + Now.Second.ToString
Dim query As String = "insert into Products values('" & id & "','" & Name & "','" & photoFilePath & "','" & Description & "','" & dt & "','" & type & "')"
Try
conn = New SqlConnection(ConnectionString)
conn.Open()
adptr = New SqlDataAdapter
adptr.InsertCommand = New SqlCommand(query, conn)
adptr.InsertCommand.ExecuteNonQuery()
Return True
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
End Class
bhagawan sahay
8-May-15 3:55am
View
hare is the complete code
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports DataOperations
Partial Class VMTAdmin_AddProduct
Inherits System.Web.UI.Page
Dim lastid As Integer
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Label9.Text = ""
lastid = GetLastId("Products")
Catch ex As Exception
End Try
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If FileUpload1.PostedFile IsNot Nothing Then
Try
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
'Save files to disk
FileUpload1.SaveAs(Server.MapPath("~/Uploads/" & FileName))
Dim result As Boolean = addDataUsingAdepter(lastid + 1, TextBox1.Text, "~/Uploads/" + FileName, TextBox2.Text, DropDownList1.Text)
If (result = True) Then
Label9.ForeColor = Drawing.Color.Green
Label9.Text = "Product Added Successfully"
TextBox1.Text = ""
TextBox2.Text = ""
DropDownList1.SelectedIndex = 0
Else
Label9.ForeColor = Drawing.Color.Red
Label9.Text = "Sorry An Error Occured"
End If
Catch ex As Exception
End Try
End If
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
DropDownList1.SelectedIndex = 0
End Sub
Public Shared Function addDataUsingAdepter(id As Integer, Name As String, photoFilePath As String, Description As String, type As String) As Boolean
Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim conn As SqlConnection
Dim adptr As SqlDataAdapter
Dim dt As String = Now.Day.ToString + "/" + Now.Month.ToString + "/" + Now.Year.ToString + " " + Now.Hour.ToString + ":" + Now.Minute.ToString + ":" + Now.Second.ToString
Dim query As String = "insert into Products values('" & id & "','" & Name & "','" & photoFilePath & "','" & Description & "','" & dt & "','" & type & "')"
Try
conn = New SqlConnection(ConnectionString)
conn.Open()
adptr = New SqlDataAdapter
adptr.InsertCommand = New SqlCommand(query, conn)
adptr.InsertCommand.ExecuteNonQuery()
Return True
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
End Class