Hi indradeo,
Check this example. Now please take its reference and correct your code.
HTML
Name:<asp:TextBox runat="server" ID="txtName" />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br /><br />
<asp:Button Text="Submit" runat="server" OnClick="Submit_OnClick" />
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void Submit_OnClick(object sender, EventArgs e)
{
string name = txtName.Text.Trim();
DateTime datetime = DateTime.Now;
string imagepath = "D:\\Image_and_File\\";
FileUpload1.SaveAs(imagepath + Path.GetFileName(FileUpload1.FileName));
string path = "D:\\Image_and_File\\Test.txt";
if (File.Exists(path))
{
string text = "Name : " + name + Environment.NewLine + "Image Name : " + Path.GetFileName(FileUpload1.FileName)+ "||DateTime:" + datetime + "" + Environment.NewLine;
File.AppendAllText(path, text);
}
txtName.Text = string.Empty;
}
VB.Net
Protected Sub Submit_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Dim name As String = txtName.Text.Trim()
Dim datetime As DateTime = Date.Now
Dim imagepath As String = "D:\Image_and_File\"
FileUpload1.SaveAs(imagepath & System.IO.Path.GetFileName(FileUpload1.FileName))
Dim path As String = "D:\Image_and_File\Test.txt"
If File.Exists(path) Then
Dim text As String = "Name : " + name + Environment.NewLine + "Image Name : " + System.IO.Path.GetFileName(FileUpload1.FileName) + "||DateTime:" + datetime + "" + Environment.NewLine
File.AppendAllText(path, text)
End If
txtName.Text = String.Empty
End Sub
Screenshot
