I have been trying to save an open excel workbook and have not been able to.I am using Visual Studio to write a program in c#. I have a windows Userform which when launches, open an excel document in a webBrowser within the form. On that userform, I created a Save button as I would like to save the changes made to the excel.
My code to open excel in webbrowser is:
private void Excelform_Load(object sender, EventArgs e)
{
// Application.DoEvents();
if (File.Exists(m_ExcelFileName))
{
webBrowser1.Navigate(m_ExcelFileName, false);
}
}
This works fine.
HOWEVER when I try to save the changes to the file I either get an error (File in or OR Operation not Executed). Tried webBrowser1.ShowSaveAsDialog(); but this requires user interaction. All I want is when the user click on the save_btn the file saves.
SO can anyone help be figure out how to save the changes made to an excel file that is currently open in a webBrowser on a userform?
Right now this is all I have:
private void toolStripButton3_Click(object sender, EventArgs e)
{
try
{
webBrowser1.ShowSaveAsDialog();
}
catch (Exception ex)
{
// Not updated
MessageBox.Show(ex.Message);
}
}
HELP PLEASE :(
Related
I've linked a Microsoft Access database to my Visual Studio project and using the data sources I have included a data grid view to modify the data. When I dragged and dropped the data grid view onto my project it automatically added the tool strip but when I try to save the modified data by pressing the save icon it won't save it permanently, meaning I can't close the program and re-open it with the same changes.
I looked at the code for the save button and even changed it to the official Microsoft support page code so it displays a message if it saves successfully and if not, however even though it's telling me it's saved correctly when I re-open the project no changes has been saved?
Here's the code for the save button I have so far:
private void modulesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.modulesBindingSource.EndEdit();
this.modulesTableAdapter.Update(this.modulesDatabaseDataSet.Modules);
MessageBox.Show("Saved succesfully","Save Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show("Unable to save. Make sure all modified data is the correct data type.","Save Failed",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
I have a web browser control in C# that it's design mode is on. I use it to make a (WYSIWYG) HTML editor. I want to insert a photo on this without UI, when user wants to insert image I show to him/her a window that shows on it some known name for user. Then with search (s)he find her/his photo and add it to control.
this is my open image form:
Photos are in database and user only know them with names. I upload all of them in a folder and show above list to user and user selects a picture. I want to add image by it's location in hard disk and allow user to set its alignment .
How I can do this ?
Adding a new element to a document is very logical. The first step is to create the node (element) you wish to append, the next is to find where you wish to append it within the document, and the final step is to actually do the appending.
I write an Example for you:
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<html><body></img></body></html>";
}
private void insert_image_btn_Click(object sender, EventArgs e)
{
HtmlElement userimage = webBrowser1.Document.CreateElement("img");
userimage.SetAttribute("src", "image location");
userimage.Id = "imageid";
webBrowser1.Document.Body.AppendChild(userimage);
}
private void btn_set_aliign_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("imageid").SetAttribute("float", "right");
}
i have a listview window browser thats working completely fine .i open folder through folder browser and the files and folders in that particular directory opens in the listview via using
PopulateListView(path)
now in my mouse double click event im opening a particular file and folder it opens the file but when it opens the directory a new window pops up .i want that directory to b opened in the listview control...the code for this scenarioa is
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string pathdoubleClicked = listView1.FocusedItem.Tag.ToString();
PopulateListView(pathdoubleClicked);
Process.Start(pathdoubleClicked);
simpleStack.Push(pathdoubleClicked);
}
now i want to do it with if else like if the path is of drectory then go to populatelistview method other wise process.start but its now working any idea how can i do this
From what I understand, if the path is a directory, you want to display its content on double-click. If it's a file, you want to open it.
So you would simply do:
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string pathdoubleClicked = listView1.FocusedItem.Tag.ToString();
if (System.IO.Directory.Exists(pathdoubleClicked))
{
PopulateListView(pathdoubleClicked);
}
else
{
Process.Start(pathdoubleClicked);
}
// ?
simpleStack.Push(pathdoubleClicked);
}
In my C# Windows application I want to upload a pdf file but in my toolbox I cannot find a FileUpload control.
How can I go about and uploading a pdf file in a C# windows application.?
regards
After you put a OpenFileDialog control on your form, let's say that you click a button and:
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
//Do whatever you want
//openFileDialog1.FileName .....
}
}
it goes something like this :-)
You can use OpenFileDialog to get the filename of the file you need and then .NET File object to read data from the file. You might need a control being able to display a PDF file. Please read the following:
Viewing PDF in Windows forms using C#
I have a WindowsForm project that is running two BackgroundWorker objects for testing if data should be collected and the collection of the data. These seem to run ok, but when I add the functionality to look at the data collected, the form freezes upon trying to graph the data available.
When clicking the first button the data is listed in a new form window with list boxes. On this new window I have another button that is for graphing the data if it seems ok.
This is where the whole project freezes. I have tried instead of soft copying the class reference that I pass into the new form, making a new object within the constructor. And as long as the data collection BackgroundWorker is not running, it appears to be working ok. When the collection is happening, clicking the plot button freezes the form, the data show button works just fine.
private void wellStatusButton1_Click(object sender, EventArgs e)
{
try
{
ListDataForm temp = new ListDataForm(tubes[0], 1);
temp.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void plotDataButton_Click(object sender, EventArgs e)
{
try
{
GraphForm plotData = new GraphForm(at);
plotData.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
It is hard to get much information from your question, but one thing that might be useful to you is this: When a windows program is doing something else in the background, usually the UI may be frozen. You can try using: Application.DoEvents() periodically, that will allow the UI to appear more responsive.