[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Writing file to directory executable is running in

Posted on 2011-05-10
3
Medium Priority
?
155 Views
Last Modified: 2012-08-14
Hi
I would like to save a file i am creating using vb studio 2010 to the same path the application is running from, code below
Using writer As StreamWriter = New StreamWriter(Log & ".txt", True)

Open in new window

0
Comment
Question by:sykotex
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35728707
if you don't specify the folder, it should automatically be there.

otherwise, try application.startuppath
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35728841
System.IO.Path.GetDirectory(System.Reflection.Assembly.GetExecutingAssembly.Location())
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35729518
If you're running Vista or Win 7 then it will cause errors trying to write to that folder.

Instead, try writing to CurrentUserApplicationData:

    Dim LogFile As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData, "Log.txt")
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question