473,671 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Efficient way to write to a text file and append?

1 New Member
I am familiar with two ways of writing to a text file so the data persists when you access it again. Adding more data (from textbox and label) will be necessary for future transactions. I'd like to learn how to write the code so I don't get an UnauthorizedAcc essException class.

I am using this way, resulting in error:

Expand|Select|Wrap|Line Numbers
  1. Dim objwriter As New System.IO.StreamWriter("C:\Customer Transactions.txt")
  2.  
  3.         objwriter.Write(txtCustName.Text, lblOrderNo, lblFinalCost)
  4.         objwriter.Close()

And there is this way (with errors again):
Expand|Select|Wrap|Line Numbers
  1.   Dim myStream As Stream
  2.         Dim saveFileDialg As New SaveFileDialog()
  3.  
  4.         saveFileDialg.Filter = ("C:\Customer Transactions.txt")
  5.         saveFileDialg.FilterIndex = 2
  6.         saveFileDialg.RestoreDirectory = True
  7.  
  8.         If saveFileDialg.ShowDialog() = DialogResult.OK Then
  9.             myStream = saveFileDialg.OpenFile()
  10.             If (myStream IsNot Nothing) Then
  11.                 myStream.WriteLine(txtFullName.Text, lblOrder, lblTotal)
  12.                 myStream.Close()
  13.                 myStream.Close()
  14.             End If
  15.         End If

I'm sure there is something I am not quite getting. Some guidance would be appreciated.
Dec 16 '13 #1
1 1313
Frinavale
9,735 Recognized Expert Moderator Expert
The Windows user that is running your application does not have permissions to create files on C:\. You need administrative privileges to change any files in the C:\ root directory.

Try writing the file into the application's executing path instead. For information about getting the application's path check out this article
[url=http://msdn.microsoft. com/en-us/library/aa457089.aspx]
HOW TO: Determine the Executing Application's Path[/icode].

You could also consider writing into the ProgramData path (for example you could try using C:\ProgramData\ YourApplication Name).

-Frinny
Dec 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5779
by: Google Mike | last post by:
I have PHP version 4.2.2 that ships with RH9. I want to have it write to a file like this: function WriteLog($sLogFile, $sMsg) { if (substr($sLogFile,1,1) != '/') { $sLogFile = realpath(dirname($_SERVER)) . $sLogFile; } `echo "$sMsg" >> $sLogFile`;
1
15009
by: Gurk | last post by:
hallow all i'm using a common dialog to save data into a text file. for so far i have this, but can someone give me a simpe exaple what i have to do after the line Open cdl.FileName For Output As #1 so itt writes some simple data. thanks Maarten On Error GoTo errhandler
1
10104
by: WebSim via .NET 247 | last post by:
Hi, I want to read a text file, and then write it into dataset. Is it possible? or Is there any solution that read text file into DB? ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>x/Vs9+Nw2U6Px6tC6dj55w==</Id>
4
3429
by: AHP | last post by:
Hi, I'm using Visual Studio 2005. I am developing a web application that uses the FileUpload control to upload text files to a directory on a webserver. This works fine. However, for me to be able to further process the files, I need to insert some data at the BEGINNING of the text file. All the solutions I've seen either append the text to the end of the file, or overwrite the data at the start of the file, or read the entire file into...
13
4177
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them from the html page (replace the words in the html page with blank space) I'm new to python and could use a little push in the right direction, any ideas on how to implement this? Thanks!
3
9566
by: mainul | last post by:
Hi guys i can write text file and also can read it. below are the codes. <?PHP //write to a file $body_content="This is my content"; // Store some text to enter inside the file $file_name="test_file.txt"; // file name $fp = fopen ($file_name, "w"); // Open the file in write mode, if file does not exist then it will be created. fwrite ($fp,$body_content); // entering data to the file
9
6932
by: andy.z | last post by:
If 2 people try to access the same text file at the same time to write to it - what happens in PHP ? What I mean is - presumably the first will be ok - But what will the second person actually see in his browser? And what will php do about it if not specifically programmed to deal with it ie whats the default behaviour?
1
1979
by: lokeshrajoria | last post by:
hello, how can i write text file text data to binary data in binary file. Thanks & Regards Lokiii
2
3065
by: Andez | last post by:
I've wrote a windows service that performs simple functions within our application. To ensure safe running of the service - if it errors we want to know where when how - it logs to a text file - in this instance BLAH.log. The code is executed within a timer which runs at 30 second intervals and polls folders. Each part of the process will log to the log file. The service will throw an IOException exception. See below for this and my...
3
3207
by: Pete Martinez | last post by:
Greetings, I need a simple method using ActiveXobject in javascript to write a text file from the local drive to my webserver. I found a method on a previous thread that copies a file from the webserver to the local drive that works but I need to reverse this. The code I found previously on the posting from "drink.the.coolaid" is as follows. ________________________________ Create a text file called c:\GetWebPage.js: var fso = new...
0
8478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8397
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.