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

Posted on 2006-04-20
Last Modified: 2008-01-09
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.
Question by:beginner80
    LVL 6

    Expert Comment


    Expert Comment

    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.

    Author Comment

    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.

    LVL 2

    Expert Comment

    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.


    Author Comment

    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.

    Accepted Solution

    Closed, 500 points refunded.
    The Experts Exchange
    Community Support Moderator of all Ages

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now