|
|
it's possible to change content of a webbrowser object in c# by using a string;
for example :
private void WriteHtml(string s){
//stream to string
MemoryStream ms = new MemoryStream();
try{
byte[] htmlcode = System.Text.Encoding.Default.GetBytes(s);
ms.Write(htmlcode,0,htmlcode.Length);
Stream dataStream = ms;
//Position
dataStream.Seek(0,0);
if(axWb.Document!=null){
//to IStream
(axWb.Document as UnsafeNativeMethods.IPersistStreamInit).Load(new UnsafeNativeMethods.ComStreamFromDataStream(dataStream));
}
}finally{
ms.Close();
}
}
modified 27-May-14 5:30am.
|
|
|
|
|
I have the following code snippet in a C# console application and am getting the following error in VS2008 on the last line (bool recExists = myReader.HasRows):
Error 2 Use of unassigned local variable 'myReader'
Here's the code:
string sResponse;<br />
SqlDataReader myReader;<br />
<br />
<br />
sQuery = "Select * from tracking where shipper_id = '" + sShipperId +<br />
"' AND shipper_ack = '" + sShipperAck + "'";<br />
<br />
myCommand1 = new SqlCommand(sQuery, conn);<br />
<br />
try<br />
{<br />
myReader = myCommand1.ExecuteReader();<br />
}<br />
catch (Exception e2)<br />
{<br />
conn.Close();<br />
conn.Dispose();<br />
<br />
sResponse = e2.GetBaseException().ToString() + " " + sQuery;<br />
<br />
}<br />
<br />
bool recExists = myReader.HasRows;
I use this same identical code in a Windows Client app with no problems.
What am I missing????
Thanks,
Dave
|
|
|
|
|
If that's a copy and paste of the code, it should work fine. I'm assuming there's something else that's not clear from what you copied and pasted. Is all of this an exact copy and paste of the whole function ?
Of course, it's not good code. You should check if myreader is null, because if execute reader blows up, it could well be.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Change SqlDataReader myReader; to SqlDataReader myReader = null; and you should be fine
|
|
|
|
|
Excellent....
That worked great, but why do I need to set the value to null in the console app and not in the Windows Forms app????
|
|
|
|
|
(Just a guess since I don't know all your code) Maybe the SqlDataReader used to be a field instead of a local? Fields are initialized automatically whereas locals aren't so they often need explicit initialization
|
|
|
|
|
Oh - yeah, I see the issue now. That is really dumb, IMO, I've had that happen too.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Try your code like this:
string sResponse;
SqlDataReader myReader;
bool recExists = false;
// Check existence of tracking record
sQuery = "Select * from tracking where shipper_id = '" + sShipperId +
"' AND shipper_ack = '" + sShipperAck + "'";
myCommand1 = new SqlCommand(sQuery, conn);
try
{
myReader = myCommand1.ExecuteReader();
bool recExists = myReader.HasRows;
}
catch (Exception e2)
{
conn.Close();
conn.Dispose();
sResponse = e2.GetBaseException().ToString() + " " + sQuery;
}
// for example
return recExists;
Hope this helps
|
|
|
|
|
change "SqlDataReader myReader;" to "SqlDataReader myReader = null;"
and try again.
modified 27-May-14 5:30am.
|
|
|
|
|
Hai friends I am facing some problems while operating powerpoint using c# application. The problem is I was able to operate the powerpoint only when I am opening it or creating it by c# application. Does any of you have ideas on how to operate the powerpoint, which is already opened in the system.
|
|
|
|
|
vijay_varma86 wrote: Does any of you have ideas on how to operate the powerpoint, which is already opened in the system.
What do you mean by operating?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
OOPS! I mean moving the powerpoint slideshow back and forth
|
|
|
|
|
I am not sure that's possible. I know you can work with powerpoint using the office toolkit, in .NET, but I don't know if Office allows an external program to find instances already running, and control them.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
This is the first time i've used a FileSystemWatcher, so i might well be doing something very basic wrong. The code below is what i use to start the FileSystemWatcher.
_fileSystemWatcher = new FileSystemWatcher(path, "*.sql");
_fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
_fileSystemWatcher.Created += new FileSystemEventHandler(FileSystemWatcher_Created);
_fileSystemWatcher.Error += new ErrorEventHandler(FileSystemWatcher_Error);
_fileSystemWatcher.EnableRaisingEvents = true;
But, i never seem to get an events raised. The path is set to the correct folder and i am creating files with an sql extension when my program runs, so i thought i would see some info.
I am running Win7, if thats any help...
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I just try your code, it works if you remove the line with "NotifyFilter".
|
|
|
|
|
Cheers.
I changed it to "NotifyFilters.FileName", as i am only interested in new files being created.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi,
but filewatcher costs process overload.
why cant you try with API Hooking
you can track all the newly opened files and even you can block creating/edit/delete file activities.
unless i know the situation for what you are using filewatcher i cant suggest even hooking.
|
|
|
|
|
The app is going to be very small. All it does is watch a folder, if new files are created, alert the user and then the user runs something in the program.
At the moment it is using 11k of memory, so i dont think this is an issue. Its also an internal app, so i know what systems it will be run on, and they are fast.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
hi,
Ya fine ! you are correct,
i have given the situation where the file watcher is done for the entire system(all the logical and removable drives)
as you mentioned for watching one folder, it wont cost performance issues.
do proceed...!
|
|
|
|
|
hi guys,
I just came across a stupid "feature" of windows installer.
it can just create advertised shortcuts when installing your application which means, any file you delete for example gets "installed" again if you run your application by clicking on that advertised shortcut.
really wonder who gave their approval to crap like this ....but this is actually not my question.
first, I want to turn this "feature" off in my installation files. I learned this is not doable by visual studio 2008 itself, hence you have to download some sdk to do it? I havent figured out yet which steps are neccessary to do this.-.. is there an example out there how to do this?
and further and even more important, I need to change he advertised shortcut on existing installations into an non-advertised shortcut! -- is this doable and if yes, how? did somebody do this before?
thanks for suggestions
best regards
pirate
|
|
|
|
|
Piratenwichtl2000 wrote: I just came across a stupid "feature" of windows installer.
it can just create advertised shortcuts when installing your application which means, any file you delete for example gets "installed" again if you run your application by clicking on that advertised shortcut.
really wonder who gave their approval to crap like this
Actually, it's quite a useful feature when users screw up their applications for you. The next tiem they launch it, it repairs itself. It's also good for kicking off a process that needs to be run on a per-user basis, such as setting up a users profile for an application.
There is no way to turn this stuff off in the Setup and Deployment project in Visual Studio. You'ld have to use a third party MSI scripting tool, such as InnoSetup, Wise for Windows Installer, InstallShield, ..., to do this. Just take the shortcut out of the shortcuts table and add it back it as a file in the Files table. You'll, of course, have to make sure that the file ends up in the correct folder in the Directory table.
|
|
|
|
|
Hi Everyone, I am facing some kind of difficulty dealing with Microsoft Excel between version.
I am working on a program that open an excel file and write in it then close it.It works fine with excel 2007 version but giving me an exception with other version ( lower than 2007).
This is how I am creating the file.
Here my code:
Microsoft.Office.Interop.Excel.Workbooks workbooks = xl.Workbooks;<br />
Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);<br />
workbook.SaveAs(System.Environment.GetEnvironmentVariable("AppData") + "\\TestFile.xls",Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8,<br />
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing,Type.Missing,<br />
Type.Missing,Type.Missing,Type.Missing);
Thanks in Advance for your help
Jashim
|
|
|
|
|
First, use the formatting tags when posting code, it makes it more readable.
What version of the interop assemblies are you using? I believe Office 2007 uses version 12. For Excel 2000 you may need an earlier version.
only two letters away from being an asset
|
|
|
|
|
Hi Mark Nischalke,
Thanks for your response. I am using the intero assemblies 12.0 as you said.
But how do I make compatible for both version at the same time. For example, I am installing this program one computer that has Excel 2002 another 2000 and 2007. So, what should I do to work with all version, if I want to.
Note: sorry for not using code properly because I am kind of new with codeproject. Don't know how to do it.
thanks again,
Jashim
|
|
|
|