3 Replies - 248 Views - Last Post: 04 November 2019 - 08:28 AM Rate Topic: -----

#1 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 16-January 13

How to set path under project folder?

Posted 04 November 2019 - 06:57 AM

One vb.net project is in d:\myorder\ in which there are references, bin, obj sub-folder.
I created a new folder under myorder project folder and named it as upload.
How to code to copy to upload folder?
The code below did not work because target path is incorrect.

SourceFile = "C:\Users\Owner\Documents\test.txt"
TargetFile = ".\upload\newtest.txt"
System.IO.File.Copy(SourceFile, TargetFile) 


Is This A Good Question/Topic? 0
  • +

Replies To: How to set path under project folder?

#2 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 394
  • View blog
  • Posts: 1,648
  • Joined: 07-September 13

Re: How to set path under project folder?

Posted 04 November 2019 - 07:02 AM

Remove the '.\'

Relative paths don't have that, you can have ..\ to tell it to go back up a directory, but no .\ as far as i am aware.
Was This Post Helpful? 0
  • +
  • -

#3 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 16-January 13

Re: How to set path under project folder?

Posted 04 November 2019 - 08:13 AM

View Postmaceysoftware, on 04 November 2019 - 07:02 AM, said:

Remove the '.\'

Relative paths don't have that, you can have ..\ to tell it to go back up a directory, but no .\ as far as i am aware.


I tried this but not working as well.
Error message said:

System.IO.DirectoryNotFoundException
HResult=0x80070003
Message=Could not find a part of the path 'upload\bar.jpg'.

 SourceFile = "C:\Users\Owner\Documents\test.txt"
TargetFile = "upload\newtest.txt"
System.IO.File.Copy(SourceFile, TargetFile) 

Was This Post Helpful? 0
  • +
  • -

#4 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 394
  • View blog
  • Posts: 1,648
  • Joined: 07-September 13

Re: How to set path under project folder?

Posted 04 November 2019 - 08:28 AM

Yeah didn't think it was going to work.

Instead of trying to use a relative path, how about using a absolute path?

You can use AppDomain.CurrentDomain.BaseDirectory to get your currently folder and then use system.io.path.combine to add on your upload\whatever

This post has been edited by maceysoftware: 04 November 2019 - 08:28 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1