C# textfile store in sqlserverVKvinoth kumar14yAsked Nov 28, 2012, 10:42 PM EST3 answersShareLinkedInXCopy linkSaveHi, I want a coding of text file is stored in database..
C# textfile store in sqlserverVKvinoth kumar14yAsked Nov 28, 2012, 10:42 PM EST3 answersShareLinkedInXCopy linkSaveHi, I want a coding of text file is stored in database..
Vithal WadjeRank #19 · 47.2K reputation14y agoPosted Nov 29, 2012, 1:48 AM EST0you can refer my article herehttp://www.c-sharpcorner.com/UploadFile/0c1bb2/uploading-and-downloading-excel-files-from-database-using-as/0
Sandeep Pant117 reputation14y agoPosted Nov 29, 2012, 2:12 AM EST0SQL CODECREATE DATABASE TextStorageDatabaseUSE TextStorageDatabaseCREATE TABLE Table1( Content varchar(400), FileName char(50))SELECT * FROM Table1C SHARP CONSOLE CODEusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Data.SqlClient;namespace UploadTextFileContentAndName{ class Program { static void Main(string[] args) { Console.WriteLine("ENTER THE FULL PATH OF File TO BE UPLOADED"); string fullPathToFile = Console.ReadLine(); Console.WriteLine("You entered the path as {0}",fullPathToFile); SqlConnection con; try { con = new SqlConnection(@"Integrated Security=True;Initial Catalog=TextStorageDatabase;Data Source=YOUR SERVER NAME"); con.Open(); string content = File.ReadAllText(fullPathToFile); Console.WriteLine("Content of all is {0}",content); string fileName = Path.GetFileNameWithoutExtension(fullPathToFile); Console.WriteLine("Your file name is {0}",fileName); SqlCommand cmd = new SqlCommand("INSERT INTO Table1 VALUES (@content, @fileName)",con); cmd.Parameters.AddWithValue("@content", content); cmd.Parameters.AddWithValue("@fileName", fileName); int result=cmd.ExecuteNonQuery(); if (result>0) { Console.WriteLine("data entered to the table"); } else { Console.WriteLine("No data entered"); } con.Close(); Console.WriteLine("Connection close"); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); } }}0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Nov 28, 2012, 11:13 PM EST
Vithal WadjeRank #19 · 47.2K reputationPosted Nov 29, 2012, 1:48 AM EST
http://www.c-sharpcorner.com/UploadFile/0c1bb2/uploading-and-downloading-excel-files-from-database-using-as/
Sandeep Pant117 reputationPosted Nov 29, 2012, 2:12 AM EST
CREATE DATABASE TextStorageDatabase
C SHARP CONSOLE CODE
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts