944,005 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 3339
  • ASP.NET RSS
Aug 31st, 2007
0

I want to create text file on clients local drive.Please help.

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mishrap is offline Offline
3 posts
since Aug 2007
Aug 31st, 2007
0

Re: I want to create text file on clients local drive.Please help.

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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 6th, 2007
0

Re: I want to create text file on clients local drive.Please help.

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mishrap is offline Offline
3 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Table Control, wats wrong
Next Thread in ASP.NET Forum Timeline: While I am Downloading ,One Dialogbox will open.When user will be saving file name...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC