Hi
based on the title,
I want my textfile created can save at any location folder .

Please help me.

Recommended Answers

All 23 Replies

are you using richtextBox to store your text???

no.
I'm using datagridview.
I mean I call each cell value in datagridview.

how far you doing this?

are you storing all the text in a string???

if yes then just use following

System.IO.File.WriteAllText("c:\\mytext.txt",strContent)

the below is the function to save and the procedure to export the file

as text file.

Dim sd As New Windows.Forms.SaveFileDialog
Private Sub savingFile()

        sd.CreatePrompt = False
        sd.FileName = lblName.Text

        sd.InitialDirectory = "C:\"
        sd.Title = "Save text Files"
        sd.Filter = "Text File|*.txt"

        If sd.ShowDialog() = DialogResult.OK Then
            Console.WriteLine(sd.FileName)
            exportProcedure(sd.FileName)
            MsgBox("The data have been saved as text file.")
        Else
            MsgBox("You are not save as text file.")
        End If
    End Sub
Private Sub exportProcedure(ByVal fileName)
           Try
            Dim bcpCommand As String

            bcpCommand = "Select Id,productcode, desc, Exclusion, 

BrandName, CostPrice, " & _
                          "from " & DbName & ".dbo.tblWare " & _
                          "Where e.Id = '" & lblId.Text & "'"

            Shell("bcp " + """" + bcpCommand + """" + " queryout " & _
               "" & fileName & " -S " & sServer & " -U sa -P Sun -c -t ^ -r \n ", 

vbHide)

        Catch ex As Exception
            MsgBox(ex.Message())
        End Try
    End Sub

it is only can save at c: but cannot at other location such as document and new folder.

the name of file is based on value at lblName.text

You can either replace line 6 from the Private Sub savingFile() with sd.RestoreDirectory = True '// restores recent Directory used. , or if you want to use the FilePath from your Label, if a full FilePath, change line 6 to sd.InitialDirectory = IO.Path.GetDirectoryName(lblName.Text) '// extract Folder Path from Full FilePath. , which should load your SaveFileDialog with that specified folder path.

it looks like can save but the text file is not exist at the selected folder or location.

I am personally a bit confused about your issue.
>>it is only can save at c: but cannot at other location such as document and new folder.

Are you trying to "only" save the file to "C:\" and nowhere else?
Or is it that you cannot save the file anywhere else other than "C:\"?

when i save it at c, it makes sense.i mean it can save at c and the file is exist.

but,when i save it at other location,it also can save but the file is not exist. the other location include at my document, new folder and other folder.

thanks

Hi
Does the user account the application is running under (you can check and configure this under IIS) have read & write permissions on the directory?

Also is this for an Intranet site or a web site? The reason I'm asking is do you really want to give someone on a website direct access to your file system?

If I need to take files in from the web I don't give anyone access to our file system, I upload them as a binary stream through a com object to a predefined directory not directly on my web server. Once I've ran a virus scan on it, I put it on our network but if the client needs to open it I again use a seperate com object to get the file as a binary stream from the network that way the end user never actually gets on our network or the servers filesystem and doesn't actually know where the files are stored. (As extra security the I store the actual files on the network with a different encoded file name.) In other words, I never just allow the user to upload a file or access an uploaded file without checking it first and then never allow direct access.

After the Location folder name use the Backward Slash(\), so that the text files that you are creating will be stored in that folder.

thank you everyone,to be clear

what i want are:
first:i want to call the value at datagrid view
second:i want to save it into the textfile
third:the text file can be save at any location such as c,d,my document, new folder and any folder.

G Waddell: owh,i see.but, mine is for windows application that using vb.net

saikalyankumar: yes, sure.but i want it flexible.it can be save at any location.i think it is because we don't know the name of folder that the user created after we deploy it.

Ok, then try saving the Required Path what you want in App.Config file. And it will be flexible to the User when you deploy to modify the Path in App.config file.

Hi
Sorry I was on the ASP.Net forum looking at a problem there before I saw this one and I must have still been in "Web Mode".

Are you allowing the user to select the file location through a dialog?

I usually allow the user to select / browse to the destination directory first then do a check that the directory does exist (and if not create it,) and then allow them to input the filename or select the source file that way I know that it is actually going to a location that does exist.

Are the users on Windows 7 machines? I've noticed that by default users only really have write access to their documents folders and you need to give thenm specific permission to write to other folders.

saikalyankumar:how to do that?

G Waddell:Yes,the user is allowed to browse the destination of directory.
no,i'm using windows xp to testing.do you know how to give the permission the user to write to other folders?

Hi
You need to assign user rights on a directory / folder level locally on a machine.
You assign the rights either on an individual level or through a group. If you open windows explorer on a machine and right click a directory, then this will bring up the properties of the directory including Sharing and Read/Write permissions.

Do you mean properties as I attached here?
after i click the textbox of 'write' permission,the result just same.


p.s://please refer to my attachment.tq

hi,
my problem is not solved yet.is everyone know to solve my problem if:

first:i want to call the value at database mssql server 2005
second:i want to save or export it to the textfile
third:the text file can be save at any location such as c,d,my document, new folder and any folder.

fourth: I will start a new thread for each question that does not relate to the topic of this thread.

hmmm..

it is related.

ok

i will open new thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.