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

My 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.
Who is Participating?
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages
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.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.