Click here to Skip to main content
15,905,776 members

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