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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.