Load .txt data from file explorer to Chart in C# - c#

I have list of array that hold the value of X & Y and it save in .txt file. I also have the button "Load data from computer".
Now i want to create function where when the user click the load button, it will open the file explorer directory, user then able to choose the file. When user click the file, the system will automatically load and plot the data in the .txt files to the chart where the graph are created.
I'm having trouble with this function,can someone help me with this function?

use openfiledialog to open the file explorer
use text reader to read the text file
use any commercial chart control to render the data to chart

Related

Choose the user a file based on file type then display in richtextbox

I'm working with file in C#. What I basically want to do is to open a folder while at the same time user can choose different file type such as (PDF, .jpg, .png, .docx) only. Then display it as a text using a richtextbox. Someone help me because I can only show one file type that user can choose.
VS Code

How to access selected file path and file name from save as dialog, in code behind?

I am using some Devexpress controls that have save options which open the browser download interface with the option of choosing "save as", opening the save as dialog. I want to save to the data base the file path and file name which were chosen for future reference. How can I access them from code behind? Also if the "save" option is chosen, how can I access the file path and name which were set by the system?
Thank you.

Limiting the files that can be selected using Open File Dialog box

I have a C# Windows Forms application where I load either a XML file or a CSV file for some task operations. When I click the Browse button I have, an Open File Dialog box appears and I can navigate to a location on my drive and choose the file and then upload it using an Upload button.
If I load a JPG or a ZIP file or any file whose format is anything except CSV or XML, my application crashes. Is there any way of limiting the Open File Dialog box to open only CSV or XML files alone in C#?
Use
openFileDialog.Filter = "CSV files (*.csv)|*.csv|XML files (*.xml)|*.xml";
this way only csv files or xml files are shown.
Odd-numbered pipes delineate between what's visible in the Filter dropdown and the corresponding actual file extension, and Even-numbered pipes delineate between the first entire file extension and the second.
For example, "CSV files (*.csv)|*csv" means users will see "CSV files (*.csv)" in the filter dropdown, and that option will look for any files that match *.csv.
In the line of code above, the pipe before "XML" indicates an entirely new filter option that will appear below the CSV option.
Nevertheless, users can also select other filetypes if they type in the complete name - so check the filename that was selected and correct your code accordingly.
You can use the Filter property to let the user choose a certain type of file.
However! This is not a guarantee. A user is still able to input '(star).(star)' in the filename box and show all files. So you should check the resulting file(s) in your code as well.
You can do this with the Path.GetExtension() method.
You can apply a filter in your Open file dialog which only shows .xml and csv files as mentioned above.
With path.getextension http://msdn.microsoft.com/en-us/library/system.io.path.getextension.aspx You can check if the user indeed selected a file with the right extension. If a wrong extension is selected, you can prompt to select a different file.
I would strongly recommend to check the file extension before upload. Just check the extension after the user had selected the file. If the wrong files was selected, just don't continue the upload/processing...

I want to make Saved File Dialog for a saved file in wpf c#, is it possible?

I have a link label in WPF C#, i want, on clicking that label, it should copy a saved file from specific folder, and save the file to some location wherever user wants to save, just like we do Save As in any software application. In SaveFileDialog class i can see that there is no option to open or copy a saved file and then to save some where else, please let me know how can i do so.
Thanks
Well you can use Open File Dialog and Save File Dialog in sequence in this scenario
First use Open File Dialog to ask user which file to copy
Then use Save File Dialog to save copied file to user defined location
The only pupose of a SaveFileDialog is to let the user choose a path and to get confirmation for overwriting existing files, everything else is your responisbility.

C#/Powerpoint add-in file select and "store"

For one part of the add-in I am creating I would like to add a video file. I am not necessarily trying to show the video in powerpoint, but I need to place this file somewhere for later reference.
So a) can I store the file within the powerpoint file, or b) if I have a relatively positioned file (same folder) could I then access the file easily?
I will be getting the file name from file open dialog.
If you want to embed the you could use the following code to add a new shape containing the video and hide it.
Dim shape As shape
Set shape = Slide.Shapes.AddMediaObject(videofile, 0, 0, -1, -1)
shape.Visible = msoFalse
However, it can be tricky to retrieve the video file later. See How to export movie from Powerpoint 2010 and VBA Export embedded video from Powerpoint presentation.
Or you could read the video data and store it in a slide or shape tag which might be an overkill depending on what you are trying to achieve.
Surely, you could copy the video file to the same directory as the PPT file but it will be lost if you move the PPT file or send it by mail etc.

Categories

Resources