• 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
              System.IO.Directory.CreateDirectory("c:\myfolder\folder1")
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.
0
beginner80
Asked:
beginner80
1 Solution
 
PreachDotNetCommented:
0
 
thespartansCommented:
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
              System.IO.Directory.CreateDirectory("\\ServerB\myfolder\folder1")
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.
0
 
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.



0
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.

 
everlaastCommented:
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.

0
 
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.
0
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

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