.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

save file in server

Posted By: Catherine     Posted Date: May 07, 2011    Points:5   Category :ASP.Net
hi this is my code which save data as notepad file in my local system c drive the same should save in
my server from the server i would like to download the file. please help


in page load
connectionstring-----------
try
{

//ECS Data to Bank - notepad generation start


string strfilepath = @"c:\ConveyanceReport-16032011.txt";
FileStream fileStream;
StreamWriter ObjtxtWriter;
if (File.Exists(@"c:\ConveyanceReport-16032011.txt"))
{
File.Delete(@"c:\ConveyanceReport-16032011.txt");
}
//fileStream = new FileStream(@"c:\EmployeeAccountsReport-" + month2.ToString() + "" + year1.ToString() + ".txt", FileMode.CreateNew, FileAccess.ReadWrite);
fileStream = new FileStream(strfilepath, FileMode.CreateNew, FileAccess.ReadWrite);
ObjtxtWriter = new StreamWriter(fileStream);

//ECS Data to Bank - notepad generation End




int tot = 0;
TableRow row = new TableRow();
TableCell cell = new TableCell();
sqlstr1 = "select accountid, mode, amount, description, month from conveyance";
da1 = new SqlDataAdapter(sqlstr1, sqlcon1);
ds1 = new DataSet();
da1.Fill(ds1);
tot = ds1.Tables[0].Rows.Count;
sqlcmd1 = new SqlCommand(sqlstr1, sqlcon1);
dr1 = sqlcmd1.ExecuteReader();
TableRow row1 = new TableRow();
TableCell cell1 = new TableCell();

while (dr1.Read())
{

ObjtxtWriter.Write("{0,14}", dr1.GetValue(0).ToString().Trim());
ObjtxtWriter.Write("{0,-14}", " INR12810000C");
ObjtxtWriter.Write("{0,17}", dr1.GetValue(2).ToString());
ObjtxtWriter.Write("{0,6}", "" + dr1.GetValue(3).ToString());
ObjtxtWriter.Write("{0,6}", "" + dr1.GetValue(4).ToString());

ObjtxtWriter.Write(ObjtxtWriter.NewLine);




}


ObjtxtWriter.Write(ObjtxtWriter.NewLine);




ObjtxtWriter.Close();

}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sqlcon1.Close();
sqlcon.Close();
}

}

Responses
Author: Mahesh             
Posted Date: May 09, 2011     Points: 20   

hi,
please follow link below,

http://www.kindblad.com/2008/04/12/how-to-store-files-in-a-ms-sql-server-database-using-aspnet

hope this may help you...

Thanks
Mahesh

Author: Rakesh             
Posted Date: May 10, 2011     Points: 20   


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend