| | |
I want to create text file on clients local drive.Please help.
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
Hi,
I have a problem which I have failed to solve.If you have time please help.I am generating text file on button's onclick.This text file is being
created on server .I want to create on the local machine (clients C:/)
See below code snippets.
***********************************************************************
Imports System.IO
Dim sw As StreamWriter
Dim strRecord,filenam As String
Protected Sub BtnTextFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnTextFile.Click
filenam = "c:\TextFiles\Name1\" & "Name-" &
DateTime.Today.Day.ToString("00") & DateTime.Today.ToString("MMM") &
DateTime.Today.Year.ToString() & DateTime.Now.Hour.ToString("00") +
DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") &
".txt"
If Directory.Exists(filenam) = False Then
Directory.CreateDirectory("c:\TextFiles\Name1")
End If
sw = File.CreateText(filenam)
sSqlString = "Select * from mstdata WHERE Convert(varchar,CreatedOn,101)
BETWEEN '" & Format(Convert.ToDateTime(txtfrmdt.Text), "MM/dd/yyyy") & "'
And '" & Format(Convert.ToDateTime(txttodt.Text), "MM/dd/yyyy") & "' order
by CreatedOn asc"
Dr = objservice.ReturnDataReader(sSqlString)
Do While Dr.Read
Dim saddress2 As String = ""
If String.IsNullOrEmpty((Dr(5)).ToString) = False Then
saddress2 = Trim(Dr(5))
Else
saddress2 = ""
End If
Dim cby As String = ""
If String.IsNullOrEmpty((Dr(10)).ToString) = False Then
cby = Trim(Dr(10))
Else
cby = ""
End If
strRecord = Trim(Dr(0)) & "|" & Trim(Dr(1)) & "|" & Trim(Dr(2)) & "|" &
Trim(Dr(3)) & "|" & Trim(Dr(4)) & "|" & saddress2 & "|" & Trim(Dr(6)) &
"|" & Trim(Dr(7)) & "|" & Trim(Dr(8)) & "|" & Trim(Dr(9)) & "|" & cby &
"|" & Trim(Dr(11)) & vbNewLine
sw.Write(strRecord)
Loop
sw.Close()
End Sub
******************************************************************
Regards
I have a problem which I have failed to solve.If you have time please help.I am generating text file on button's onclick.This text file is being
created on server .I want to create on the local machine (clients C:/)
See below code snippets.
***********************************************************************
Imports System.IO
Dim sw As StreamWriter
Dim strRecord,filenam As String
Protected Sub BtnTextFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnTextFile.Click
filenam = "c:\TextFiles\Name1\" & "Name-" &
DateTime.Today.Day.ToString("00") & DateTime.Today.ToString("MMM") &
DateTime.Today.Year.ToString() & DateTime.Now.Hour.ToString("00") +
DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") &
".txt"
If Directory.Exists(filenam) = False Then
Directory.CreateDirectory("c:\TextFiles\Name1")
End If
sw = File.CreateText(filenam)
sSqlString = "Select * from mstdata WHERE Convert(varchar,CreatedOn,101)
BETWEEN '" & Format(Convert.ToDateTime(txtfrmdt.Text), "MM/dd/yyyy") & "'
And '" & Format(Convert.ToDateTime(txttodt.Text), "MM/dd/yyyy") & "' order
by CreatedOn asc"
Dr = objservice.ReturnDataReader(sSqlString)
Do While Dr.Read
Dim saddress2 As String = ""
If String.IsNullOrEmpty((Dr(5)).ToString) = False Then
saddress2 = Trim(Dr(5))
Else
saddress2 = ""
End If
Dim cby As String = ""
If String.IsNullOrEmpty((Dr(10)).ToString) = False Then
cby = Trim(Dr(10))
Else
cby = ""
End If
strRecord = Trim(Dr(0)) & "|" & Trim(Dr(1)) & "|" & Trim(Dr(2)) & "|" &
Trim(Dr(3)) & "|" & Trim(Dr(4)) & "|" & saddress2 & "|" & Trim(Dr(6)) &
"|" & Trim(Dr(7)) & "|" & Trim(Dr(8)) & "|" & Trim(Dr(9)) & "|" & cby &
"|" & Trim(Dr(11)) & vbNewLine
sw.Write(strRecord)
Loop
sw.Close()
End Sub
******************************************************************
Regards
You cannot save a file directly to the users machine, in an HTTP web environment you do not have access to a users file system and no user would want you to have that ability either. Having created the file on the server you need to give your user a link to click or redirect to a download page for that file, and let the user save it to their file system.
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
While I am Downloading ,One Dialogbox will open.When user will be saving file name...that time I want to restrict user to change the file name ..I have written code below for downloading file.
Dim fs As System.IO.FileStream = Nothing
fs = File.Open(Server.MapPath("TextFiles/Branch/" + filenam + ".txt"), System.IO.FileMode.Open)
Dim btFile(fs.Length) As Byte
fs.Read(btFile, 0, fs.Length)
fs.Close()
With Response
.AddHeader("Content-disposition", "attachment;filename=" & filenam)
.ContentType = "application/octet-stream"
.BinaryWrite(btFile)
.End()
End With
With Regards,
mishrap
Dim fs As System.IO.FileStream = Nothing
fs = File.Open(Server.MapPath("TextFiles/Branch/" + filenam + ".txt"), System.IO.FileMode.Open)
Dim btFile(fs.Length) As Byte
fs.Read(btFile, 0, fs.Length)
fs.Close()
With Response
.AddHeader("Content-disposition", "attachment;filename=" & filenam)
.ContentType = "application/octet-stream"
.BinaryWrite(btFile)
.End()
End With
With Regards,
mishrap
![]() |
Similar Threads
- Help with appending text file (VB.NET)
- turning userinput into a text file (C)
- How do you create a text file? (C)
- Generate file in memory to save to local disk (ASP.NET)
- Output in Text file-How to apply fprintf()? (C)
- Create stats from a text file (Java)
- 10 line text file (Java)
Other Threads in the ASP.NET Forum
- Previous Thread: Table Control, wats wrong
- Next Thread: While I am Downloading ,One Dialogbox will open.When user will be saving file name...
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# c#gridviewcolumn cac checkbox commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist development dgv dropdownlist dropdownmenu dynamically edit fileuploader fill flash flv formatdecimal forms formview gridview gudi homeedition iframe iis javascript jquery listbox menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news objects opera panelmasterpagebuttoncontrols redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice youareanotmemberofthedebuggerusers






