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!
Reply

Join Date: Aug 2007
Posts: 3
Reputation: mishrap is an unknown quantity at this point 
Solved Threads: 0
mishrap mishrap is offline Offline
Newbie Poster

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

 
0
  #1
Aug 31st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

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

 
0
  #2
Aug 31st, 2007
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: mishrap is an unknown quantity at this point 
Solved Threads: 0
mishrap mishrap is offline Offline
Newbie Poster

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

 
0
  #3
Sep 6th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC