1

I have a project where I get a list of file location strings that I want to save locally. I want to use a FileUploader to do so. I am trying something like this so far:

            FileUpload filesaver = new FileUpload();

            //Iterate over each files (InputFiles is a linked list of file locations)
            foreach (string File in InputFiles)
            {
                //Get file
                Stream fileLoaded = OpenFile(File);

                filesaver.FileContent = fileLoaded;

                //Save file                    
                filesaver.SaveAs(DownloadLocation);

                //Code...}

The problem is that filesaver.FileContent = fileLoaded; is not a valid call (FileContent is read only).

How would I be able to get the file to the file loader so that I can save it if I have a string of that file location?

Edit I am using the FileUpload Class

3
  • Are you using the asp.net file uploader ?! Commented Aug 9, 2011 at 14:39
  • are you in asp.net or windows forms? if you want to save a file to a certain location can't you use streams? Commented Aug 9, 2011 at 14:39
  • asp.net. I am using this Commented Aug 9, 2011 at 14:40

2 Answers 2

1

The ASP.NET FileUploader has the client side send the file to the server side. It does not send a file path as a string, so there is no way to intercept the file path and "upload" on the server side. if that is your intent, you are not going to find a way to get there from here.

If you want to save the actual file binary bits once it gets to the server, there are plenty of examples out there that persist the data to databases or file system.

If you are trying to get paths as strings, the file uploader is not your best choice, but note that the file path strings, if they are local to the client, are of no use on the server side.

Sign up to request clarification or add additional context in comments.

Comments

1

You can just use:

If (filesaver.HasFile)
{
        filesaver.SaveAs("C:\YourFilePath\" & filesaver.FileName);
}

3 Comments

This does not answer the problem the user is having.
When you set up a FileUpload in ASP.NET, the file will be there. Follow the code examples on the page you linked.
@Peppered You don't set the file in your code. Once the client selects a file in their browser, it's set. Note that the code above should be called in response to an event (like a submit button click). It doesn't upload when the user selectes their file on the client side

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.