Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:30:17+00:00 2026-05-16T01:30:17+00:00

I’m trying to create a custom file upload control in WPF 4.0 and I’m

  • 0

I’m trying to create a custom file upload control in WPF 4.0 and I’m stuck in one point.
I’m not able to save file in my solution folder after browsing the file. Below code I’m using for Browsing

private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = "Images (*.JPG;*.JPEG;*.PNG)|*.JPG;*.JPEG;*.PNG";
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                string filename = dlg.FileName;
                FileNameTextBox.Text = filename;
            }
        }

 private void btnUpload_Click(object sender, RoutedEventArgs e)
        {

            string filename = FileNameTextBox.Text;
           // Now I want save this file to my image folder.
        }

Now I want to save file in image folder which is inside my Solution explore. For ASP.NET we use Server.Mappath for mapping the specified relative or virtual path to the corresponding physical directory on the server. But I’m not sure what we can use in WPF for achieving the same thing. I’m new in WPF so please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:30:17+00:00Added an answer on May 16, 2026 at 1:30 am

    If you are talking about WPF, and not Silverlight, then it is important to understand the distinction between WPF and ASP.NET. ASP.NET is a hosting platform for the HTTP protocol. Paths in an ASP.NET site are not necessarily directly represented on disk, so Server.MapPath provides a way to map an ASP.NET path to a phsyical path.

    WPF, on the other hand, is plain and simply a UI framework. It is not a hosting environment like ASP.NET, so the concept of mapping paths is irrelevant in the context of WPF. Based on the code you provided, you are not “uploading” a file, you are simply opening a file. In WPF, your applications logic is running directly on a users system, and therefor you have access to the file system via the System.IO namespace. You can create a new file using the FileStream class and copy bytes from the source to your new file manually, or simply copy the “opened” file using the File class. Your WPF UI is providing a window into a normal “desktop” application, so uploading files need not (and most likely will not) occur when you open or save a file.

    Keep in mind, as your application is a desktop application, you will be limited by the permission set of the user running your application. If the user running your application does not have permission to write somewhere on disk, then you will encounter exceptions when trying to write. The same goes if they do not have permission to read or delete files from somewhere. Make sure any file activities you perform are done in areas of the file system that the user has permission, such as their documents folder.

    public void btnUpload_Click(object sender, RoutedEventArgs e)
    {
        string filename = FileNameTextBox.Text;
        if (File.Exists(filename))
        {
            // TODO: Show an error message box to user indicating destination file already uploaded
            return;
        }
    
        string name = Path.GetFileName(filename);
        string destinationFilename = Path.Combine("C:\\temp\\uploaded files\\", name); 
    
        File.Copy(filename, destinationFilename);
    
        // TODO: Show information or message box indicating file has copied
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.