|
I guess I am out of luck since I am trying to display a stream of image and a pdf. Oh well, thanks.
|
|
|
|
|
You're not out of luck - there's just not a simple solution. The WebBrowser control is an ActiveX container and hosts things like MSHTML (the rendering engine for IE), Word, Acrobat (Reader), etc. It involves getting RCWs (runtime callable wrappers - a managed interface wrapping a native COM interface) and loading an IPersistFile interface (or a small handful of other, similar interfaces). Of course, you could always just navigate to the file and IE (a la the WebBrowser control) will take care of the rest.
For the former method, search for "WebBrowser.DocumentStream" and you'll find some helpful tips.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
First, I apologize if this is not the proper forum to ask my question.
I have a .NET 2.0 Windows Form App which uses BindingNavigator, BindingSource and DataSet.
The user can use the AddNew and Delete buttons of the BindingNavigator to Add/Delete records to the underlying typed DataSet.
In my particular case, I'm showing a Work Order record whose PK is also the table's IDENTITY field (MS SQL 2005).
My DataSet is setup with negative increment for this PK in order to avoid clashes.
So, when the user clicks the AddNew button, he sees a negative Work Order number showing up until the Update method is called on the TableAdapter. This could be a source of confusion in some users, so I'd like to proceed differently.
Should I handle this field manually, getting from the DB the highest Work Order number right when the record is created in the DataSet ? If so, how do I take care of concurrency in the case another user also creates a new Work Order before first user actualy commits his new record ?
Or should I simply call Update right away when the record is created ?
I assume this is a very common issue in DB programming.
Thank for any tips.
Luc Morin
|
|
|
|
|
There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time.
If you handle the id manually, you still won't get it right all the time. Sometimes some other user will have created a record, so the insert will fail. Then you would have to handle the error condition, give the id a new number and try to save it again. This might be acceptable, but one big drawback is that the more users you have, the more frequently this will happen.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time.
Yes, this is exactly my concern.
How do most apps handle this situation ? I was thinking of making the Work Order TextBox invisible until the user actuallty saves the record.
What do you think ?
Regards,
Luc Morin
|
|
|
|
|
You could make a call to a stored procedure that just creates a blank record in the table. The autoincremented value (ID) gets created, then the SP returns just that ID. You're code can then show a blank edit form so all the details can be filled in. Then the record can be written back to the table with the "checked-out" ID number.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I’m missing something (I’m experienced with C, C++ but not with C#, ASP.NET)...
I want to dynamically create a control/random HTML. Do I have to do it with, for example,
<br />
HtmlTable table1 = new HtmlTable();<br />
table1.Attributes.Add("border", "0");<br />
table1.Attributes.Add("align", "center");<br />
div1.controls.Add(table1);<br />
etc. or can I pass ‘<table border=”0” align=”center”>...</table>’ to something and have it render it?
Rog
-- modified at 14:41 Friday 20th January, 2006
|
|
|
|
|
You don't have to render it if it's already html code. You put it on the page.
Use for an example a placeholder:
<asp:Placeholder id="Arthur" runat="server"/>
Add a literal control containing the html code:
Arthur.Controls.Add(new LiteralControl("<table ... > ... </table>"));
---
b { font-weight: normal; }
|
|
|
|
|
Excellent, thank you.
I already have an 'Arthur' to hang things off. So, to do the dynamic bits, I can just adjust the string or use Arthur.FindControl("x") afterwards to adjust it.
It's these things like not knowing about LiteralControl which are the 'things you don't know you don't know' that make forums like this so worthwhile!
Thanks again.
Rog
|
|
|
|
|
I want to design a program that operate in the following:
click a button--> OpenFileDialog, chose the pic that u want to copy.... If DialogResult.OK --->the selected picture is copied to folder \bin\debug with the name "copied.gif"
Help me, pleaseeeee
|
|
|
|
|
So what's your problem? A picture is a file just like any other so just use File.Copy. Or did you want to convert formats?
|
|
|
|
|
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "Image files|*.tif;*.tiff;*.bmp|All files (*.*)|*.*";
if (openFile.ShowDialog() == DialogResult.OK)
{
File.Copy(openFile.FileName, Application.StartupPath +"\\coped.gif");
}
-- modified at 15:45 Friday 20th January, 2006
|
|
|
|
|
and...
how to create a folder and save my file to that folder???
In OpenFileDialog, filter, how to display in the textbox "File of type" like:
Image File (*.gif;*.jpg;*.bmp)
thanks
|
|
|
|
|
Before saving a file to a particular folder, it is a good practice that you check the folder's existence.
Review the following code:
string MyFolderDir = "C:\\MyFolder\\";
if(!Directory.Exists(MyFolderDir )) // if your folder does not exist
{
Directory.Create(MyFolderDir); // create the folder on the specified directory
}
In the "File of Type" dropdown, you just need to specify the text that would appear and the filter. You can separate them using the "|" character. Like this:
openFile.Filter = "Image File (*.gif;*.jpg;*.bmp)|*.gif;*.jpg;*.bmp";
Microsoft KB and other sites such as this have very good articles about File operations. Try exploring. Enjoy!
-- modified at 9:45 Saturday 21st January, 2006
|
|
|
|
|
I don't understand the Format property on the defaultCellStyle of the column I just added to a dataGridView.
I have it set to Currency with 2 decimals, thus "C2".
I fire up my project, double click in the cell, put in 5 and it doesn't format it to '$5.00'. Why not?
Am I totally missing something?
|
|
|
|
|
Is it possible to make a class in visula basic . net and include it in c# project and make its obect in C# for calling its method
|
|
|
|
|
Sure. The VB.NET class just has to be it's own project. Then, in your C# project, you can set a project (preferrably) reference to the VB.NET project and include the class just like any other pre-written namespace and class in the .NET Framework.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hey everyone...
i've probably missed something very important, and just don't know it.
the reason: i'm trying to populate 2 treeviews from 2 separate threads with separate data in each, both trees are pretty slow to load so i need the threads, else i lock up the ui for about 10sec. I also have to refresh the trees throughout the progress so i've had to build the threads the way i have so i can access it later.
the problem: if i try to invoke both threads in the same form_load block i end up with 2 trees with the same data. if i invoke them separately (comment one or the other out) i have proven that the code works properly for both, so it leads me to believe that i've either done something terribly wrong or i just can't do what i'm trying to do........
any ideas?
here is the code:
Thread PcTree, pclist,EmpTree,emplist;
MethodInvoker CallCompList, CallEmpList;
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
switch (tabControl1.SelectedIndex)
{
case 0:
initializePcTree();
break;
case 4:
initializeEmpTree();
break;
}
}
private void initializePcTree()
{
PcTree = new Thread(new ThreadStart(PopComputerList));
PcTree.IsBackground = true;
PcTree.Name = "PcTree";
PcTree.Start();
}
private void initializeEmpTree()
{
EmpTree = new Thread(new ThreadStart(PopEmpList));
EmpTree.IsBackground = true;
EmpTree.Name = "EmpTree";
EmpTree.Start();
}
private void PopComputerList()
{
CallCompList = new MethodInvoker(CompList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallCompList);
}
private void PopEmpList()
{
CallEmpList = new MethodInvoker(EmpList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallEmpList);
}
private void newCompList()
{
CompList();
}
private void newEmpList()
{
EmpList();
}
private void CompList()
{
statusBarPanel1.Text = "Please Wait While We Update the List";
PCmonitorTree.Nodes.Clear();
ParentNode = new TreeNode("TopNode");
PCmonitorTree.Nodes.Add(ParentNode);
foreach(SearchResult sr in ds.FindAll())
{
TreeNode PCnode = new TreeNode();
PCnode.Text = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
ParentNode.Nodes.Add(PCnode);
TreeNode PCnode1 = new TreeNode();
PCnode1.Text = "PC - " +sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
PCnode1.Tag = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
PCnode.Nodes.Add(PCnode1);
PCmonitorTree.Sorted = true;
}
PCmonitorTree.ExpandAll();
t = ParentNode;
PCmonitorTree.SelectedNode = t;
statusBarPanel1.Text = "Ready";
}
private void EmpList()
{
statusBarPanel1.Text = "Please Wait While We Update the List";
empTree.Nodes.Clear();
TreeNode ParentNode = new TreeNode("TopNode");
empTree.Nodes.Add(ParentNode);
foreach(SearchResult sr in ds.FindAll())
{
DirectoryEntry DE = sr.GetDirectoryEntry();
TreeNode empnode = new TreeNode();
empnode.Text = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
empnode.Tag = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
ParentNode.Nodes.Add(empnode);
empTree.ExpandAll();
empTree.Sorted = true;
}
t=ParentNode;
empTree.SelectedNode = t;
statusBarPanel1.Text = "Ready";
}
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
You cannot call methods on Controls created on another thread. T do this, you have to use the Invoke methods of the Controls.
See this: http://blogs.wwwcoder.com/amachin/archive/2004/12/15/1146.aspx[^]
EDIT: Sorry, misread your article. You are using BeginInvoke, this should work. Anyway, you probably should read the article linked above, it may solve your issue.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 12:06 Friday 20th January, 2006
|
|
|
|
|
private void PopComputerList()
{
CallCompList = new MethodInvoker(CompList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallCompList);
}
private void PopEmpList()
{
CallEmpList = new MethodInvoker(EmpList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallEmpList);
}
Look what you're doing here with the de and ds variables. You're using a class scoped de and ds variables. DON'T! Each thread should create and use it's own set of Directory objects scoped within the methods themselves.
What's happening is that when you launch your first thread, it sets up the de and ds variables to perform a search. While that setup and search is taking place, you launch another thread that, low and behold, reassigns new DirectorySearcher and DirectoryEntry objects to the very same de and ds variables you just setup in your previous thread. Global variables - bad idea...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 12:26 Friday 20th January, 2006
|
|
|
|
|
Good point Dave,
I think i picked up that bad habit from those redim-ing vb guys i work with
problem fixed!
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
I'm calling a method that can throw one of several exceptions:
byte[] ReadFile(string filePath)
{
return File.ReadAllBytes(filePath);
}
When calling this method, do you guys usually catch every possible exception, or just cover it with a single catch block? For example, do you do this:
string errorMessage = null;
try
{
return File.ReadAllBytes(filePath);
}
catch (ArgumentException argumentError)
{
errorMessage = argumentError.Message;
}
catch (ArgumentNullException nullArgumentError)
{
errorMessage = nullArgumentError.Message;
}
catch (PathTooLongException pathError)
{
errorMessage = pathError.Message;
}
catch (DirectoryNotFoundException directoryNotFoundError)
{
errorMessage = directoryNotFoundError.Message;
}
catch (IOException ioError)
{
errorMessage = ioError.Message;
}
catch (UnauthorizedAccessException unauthorizedError)
{
errorMessage = unauthorizedError.Message;
}
catch (FileNotFoundException fileNotFoundError)
{
errorMessage = fileNotFoundError.Message;
}
catch (NotSupportedException notSupportedError)
{
errorMessage = notSupportedError;
}
catch (System.Security.SecurityException securityError)
{
errorMessage = securityError;
}
if(errorMessage != null)
{
MessageBox.Show(errorMessage, ...);
}
Or do you catch it all in a single System.Exception catch block?
try
{
File.ReadAllBytes(filePath);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, ...);
}
Obviously the latter is easier to read and write, but the former is more precise and won't eat up things like system errors (OutOfMemoryException, OverflowException, etc.). Which do you guys suggest?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
It depends. For example, when reading a file I'll normally check it exists first, so I a PathTooLongException, DirectoryNotFoundException and FileNotFound are really things I should not be getting, so they'd be covered in a catch all (if at all at that point in the code). Specific things that I can't check for in advance would be in specific blocks.
On the whole I find that exceptions propogate up a couple of method calls in the stack before I actually handle them because often at the point the exception occurs I am not able to handle it so I allow it to propogate up until I can do something about it.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Or in case of IO operation it would be better to do:
catch (IOException ex)
{
.. io error occured. PathTooLongException and all other IO related inherit from IOException
}
catch (Exception ex)
{
.. all other unexpected errors
}
|
|
|
|
|
My example was simplified; my real code has the error propagating up a ways until it gets to the UI as well.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|