• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5583
  • Last Modified:

how to check directory exist, create directory, upload file to remote server in vb.net

My vb.net application is on server A, and from the application there, user will upload image and that file needs to be saved on another media server which is server B. How to do that? Previously I check the directory, create new directory and save the image on the server A by using these codes:

If Not System.IO.Directory.Exists("c:\myfolder\folder1") Then
End If
myFile.PostedFile.SaveAs("c:\myfolder\folder1\" & myFile.PostedFile.FileName)

But now I have to save the image/file on another server. Which method should i use? I did try to use webclient:

myWebClient.UploadFile("http://serverb/folder", myFile.PostedFile.FileName)

this gave me method not allowed (405) error. And I read from some articles stating that by using web client we need to write an web page on the server to recieve the file and write it
to the directory but this is not excatly what I want. On the server b, there is only a folder to keep all images/files but no any other application/web page.

Urgent helps needed. Please advice.
1 Solution
You could just share the media directory on Server B and then access it from Server A using the UNC address. So your existing mechanism would change to look like:

If Not System.IO.Directory.Exists("\\ServerB\myfolder\folder1") Then
End If
myFile.PostedFile.SaveAs("\\ServerB\myfolder\folder1\" & myFile.PostedFile.FileName)

Obviously the share will have to have suitable permissions set for the app on Server A to access and write to the directory.

If you are using Windows on Server B then you can do all this through Windows File and Print Sharing. If not you will need to look into something like Samba.
beginner80Author Commented:
Hi the partans,

I did try to use this way:
If Not System.IO.Directory.Exists("\\ServerB\myfolder\folder1") Then
              System.IO.Directory.CreateDirectory("\\ServerB\myfolder\folder1") <-- error
End If

Error prompted on this line : System.IO.Directory.CreateDirectory("\\ServerB\myfolder\folder1")

error message is: Could not find a part of the path "\\ServerB\myfolder

Server A (where application is running on) has full permission on shared folder on server B which is myfolder, but I still get the said error.

Beside from using shared folder, is it others way to create new directory and save files on remote server?

Thanks for any helps.

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Server cannot have permissions on other server.
An user on the first server can have permissions accessing the other server.
Are you sure your application is running in the correct users rights.

beginner80Author Commented:
Thanks for comments from experts but unfortunately no single solution can fix my problem. I did try another way to solve by requesting system admin to pull the content from local server to remote server, meanwhile I am still upload my image to local server. I hope that this solution is acceptable.
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now