wpf controls - File uploader in WPF -
I am trying to create a custom file upload control in WPF 4.0 and I'm stuck in a point.
After browsing the file, I can not save the file in my Solutions folder. Below are code I'm using for browsing
Private Zero btnBrowse_Click (Object Sender, RoutedEventArgs E) {// OpenFileDialog Microsoft.Win32.OpenFileDialog.dlg = New Microsoft.Win32.OpenFileDialog ( ); Dlg.Filter = "Picture (* .JPG; * .JPEG; *. PNG) * .JPG; * .JPEG; *. PNG"; By tap & lt; Bool & gt; Results = dlg.ShowDialog (); If (result == true) {string filename = dlg.FileName; FileNameTextBox.Text = Filename; }} Private Zero btnUpload_Click (Object Sender, RoutedEventArgs e) {string filename = FileNameTextBox.Text; // Now I want to save this file in my image folder. }
Now I want to save the file to the image folder, which is the solution inside my solution. For ASP.NET, we use Server.Mappath to map relative or virtual paths that are specified in the respective physical directory on the server. But I'm not sure what we can use in WPF to achieve the same thing. Help me if I am new to WPF.
If you are talking about WPF, then not Silverlight, then WPF and ASP.NET It is important to understand the differences between the two. ASP.NET is a hosting platform for HTTP protocols. I do not necessarily have a path in an ASP.NET site that are directly represented on the disk, so Server.MapPath does a way to map an ASP.NET path to a phsyical path Provides for
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 path is irrelevant in the context of WPF. Depending on the code provided by you, you are not " uploading " a file, you just open a file in WPF, your application logic directly to the user system , And for this you have access to the file system through the system .iO namespace. You can use a class to create a new file and manually copy your new file from the source or copy the "opened" file using the class. If your WPF UI is providing a window in a normal "desktop" application, then there is no need to upload files (and most likely not), when you open or save a file.
As an application, keep in mind that there is a desktop application, you will be limited by the permission of the user's set up your app. If users are not allowed to type on your disk to play your application, then you have to face exceptions while trying to write. The same goes, if they are not allowed to read or delete files in any way, make sure that any file is performed in the areas of the activities you file in the form of your documents folder such that the user has permission of the file system Please.
Public Zero btnUpload_Click (Object Sender, RoutedEventArgs E) {string file name = FileNameTextBox.Text; If (File.Exists (filename)) {// TODO: Show an error message box for the user already indicating the destination upload file; } String name = path Gatefilename (filename); String destinationFilename = Path.Combine ("C: \\ temp \\ uploaded files \\", name); File.copy (filename, destination name); // TODO: Info or message box showing the file has been copied}
Comments
Post a Comment