Wednesday, 3 January 2024

Upload Text File .txt and .log

Leave a Comment

I will demonstrate how to upload a delimited file into the database in this article.

ASPX
The upload file tool and one button have recently been introduced. Code is shown below.

Uploader of Files


<asp:FileUpload ID="FileUpload1" runat="server" BorderColor="Black" BorderStyle="Solid" Width="303px" BackColor="white" CssClass="form-control" />

Button

<asp:Button ID="btnUploadFile" runat="server" Text="Upload"  OnClick="btnUploadFile_Click" CssClass="btn btn-success button-62" />

Now, we will write the code behind the file upload function.

Code Behind

On button click we will call the file reader function.

string[] lines = File.ReadAllLines(file_Path + file_Name);

This reads all lines function will read text files from top to bottom.

Now, from here, we have to write the logic to split the file column into cells. suppose your file has 3 columns.

for (int i = 0; i <= lines.Length - 1; i++)
{
    // Note this is the separation we have file with separation [:]
    string[] lines_data = lines[i].ToString().Split(':');

    strsql = "INSERT INTO tableName(col1,col2,col3)";
    strsql += $"VALUES('{lines_data[0].ToString().Trim()}', '{lines_data[1].ToString().Trim()}', '{lines_data[2].ToString().Trim()}', '{Source_File_Name.ToString().ToUpper()}')";
    Flag = obj.GetNonScalar(strsql, obj._ConnIND).ToString();
}

All done, it will read the file successfully.

Thanks for watching. please feel free to ask any questions.

This will not have any output screen to share. it will directly link to database tables.

Best ASP.NET Core 8.0 Hosting Recommendation

One of the most important things when choosing a good ASP.NET Core 8.0 hosting is the feature and reliability. HostForLIFE is the leading provider of Windows hosting and affordable ASP.NET Core, their servers are optimized for PHP web applications. The performance and the uptime of the hosting service are excellent and the features of the web hosting plan are even greater than what many hosting providers ask you to pay for. 

At HostForLIFEASP.NET, customers can also experience fast ASP.NET Core hosting. The company invested a lot of money to ensure the best and fastest performance of the datacenters, servers, network and other facilities. Its datacenters are equipped with the top equipments like cooling system, fire detection, high speed Internet connection, and so on. That is why HostForLIFEASP.NET guarantees 99.9% uptime for ASP.NET Core. And the engineers do regular maintenance and monitoring works to assure its Orchard hosting are security and always up.

0 comments:

Post a Comment