Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone!

Can you please help me regarding my problem here. I have an application created in vb2008 and I'm trying to Upload or Copy a file from my server to my client.

My code goes like this:

VB
My.Computer.Network.UploadFile("D:\Image\Pic.jpg","\\10.0.0.2\D$\Image\Pic.jpg")


I'm working on a Windows 7 OS. My code works on some computer, but when I tried to execute my command on both windows 7 an error occured saying "Access Denied..."

What seems to be the problem?
Can anyone suggest me a solution about this problem?

Thank You in advance...
Posted

1 solution

Of course it would be denied! This directory or drive letter does not have to exist on all systems.

In general case, such directory can be illegal on Windows 7. Moreover, there are no situations when using hard-coded path names, relative or absolute, can be useful. Path names should always be calculated during run time based on user input, configuration data and some special directories associated with the installation or user accounts, including the directories reserved for all users.

I provide comprehensive description on how to get all such directories in my past answers:
How to find my programs directory [ executable directory ],
How to find my programs directory [ "special folders", working directory ].

See also:
How to access a file from html folder of root directoty[^],
which is better : use of registery in order to store setting or use of Settings class[^],
Cant find 'installallusers' property[^].

—SA
 
Share this answer
 
v2
Comments
Member 9421129 9-Feb-13 3:44am    
Assuming both computers has drive D:, I wanted to simply copy "D:\Image\Pic.jpg" (serve as client) on a computer (server) with an IP 10.0.0.2 , on same directory as the client.,,,
Sergey Alexandrovich Kryukov 9-Feb-13 12:36pm    
Then just stop wanting it; want something which makes sense. You hard-code it but still thinks it can work on other computer. If there is not "D:", how can it work. You just created non-working application, no matter for Window 7 or not. Fix it. Add a file dialog, for example...
—SA
Member 9421129 12-Feb-13 6:59am    
I found the solution my self...it's pretty simple...Thanks for your comments and feedback...
Sergey Alexandrovich Kryukov 12-Feb-13 11:11am    
Great, but will you accept my answer formally (green button)? These are the important instruction you should follow in all cases.
Good luck, call again.
—SA
Sergey Alexandrovich Kryukov 12-Feb-13 11:13am    
By the way, I cannot say your solution is a good one. Developing in this style, you cannot really deploy your solutions, will rely on manual operations... you really need to do what I advised.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900