|
Hi,
I got the file in binary format from db.Now i want to save this file in some location given by the user by a file save as dialog option without opening it.
String new_FileName = Path.ChangeExtension(Path.GetTempFileName(), filetype);
File.WriteAllBytes(new_FileName, result);
FileDialog fldlg = new SaveFileDialog();
fldlg.InitialDirectory = "c:\\";// @" \";
fldlg.Filter = "*.jpg|*.gif|*.txt|*.doc|*.pdf|*.htm";
fldlg.FileName = filename;
This is my code.I did like this
But file is not saving
|
|
|
|
|
What exactly you are trying to do?
SaveFileDialog doesnt saves anything. It only shows the dialog box.
You need to use fldlg.ShowDialog to show dialog and ask user to select a filename.
Then you need to copy the file into its new location specified by user using system.IO.File.Copy(new_FileName, fldlg.FileName) or sort of.
|
|
|
|
|
Thanks a lot.I didnt copy the code for showDialog.I was using some stream and all and it wasnt worked.I changed the code now using File.copy and it is working fine.thanks a lot
|
|
|
|
|
hi,
I have already posted the message in this link : http://www.codeproject.com/Messages/3532775/exe-update.aspx[^]
but a few more clarifications needed,
I have developed one windows application which is installed in more than 500 machines using setup and deployment process(.exe or .msi). Now i have made some alterations in my appliacation so that i dont want to reinstall it again. Is there any way to do, that when i change the code here it should refelct in all the machines silently....
|
|
|
|
|
AFAIK, there is no way to do this now.
As was recommended earlier, Clickonce Deployment can help you achieve automatic updates.
|
|
|
|
|
You are going to have to redeploy everytime you release the project.
There are ways to automate this, the easiest is to design a very simple wrapper that checks for updates and installs if nescessary, then launches the main program.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Thanks for your reply,
Can you provide me with some samples
|
|
|
|
|
I have a database table that is bound to a report. One of the fields is an Int32 type that stores the id of a jpg image. This has been done to reduce database storage.
I know I can create a runtime column and fill it with the appropriate images but there's a performance issue with that. The images are fairly large so I would like to store them as a WeakReference. (Or some kind of dynamic access)
Can anything be acomplished along this line? Anything!
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
Check out the Low impact images article by Pete O'Hanlon. It's neat.
Also check out Sacha's reply/message.
Should help in the Weak Reference
I bug
|
|
|
|
|
Hi everyone. My question is quite simple. I would like to know how exactly you would handle multiple types of exceptions in a method. Is this correct:
try
{
}
catch (FileNotFoundException fnf)
{
}
catch (ArgumentNullException ane)
{
}
catch (SomeException se)
{
}
I know it works. However, is that the best way to do it? I am asking because the exceptions that are thrown by different file operations, such as File.Open, are quite different from the types thrown by MessageBox.Show, for example. Or should I perform file operations and catch exceptions then perform other operations and catch their exceptions and so on?
Thanks in advance!
|
|
|
|
|
My approach has always been to do as much of mine own validation as possible. This prevents try/catch nesting that you've described.
For example, perform your own validation on the filepath and throw one ArgumentException:
try
{
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
throw new ArgumentException("A meaningful message goes here...")
}
catch (Exception ex)
{
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
Alright, thanks for the timely response. I understand what you're saying. What about other operations that I can't check beforehand, such as UnauthorizedAccessException? If it can't be detected by something such as "string.IsNullOrEmpty(string)" or any other safety statement should I catch the appropriate exception then?
|
|
|
|
|
Hi,
IMO there is no best way, you should do whatever you think fits the functionality. Say it is all part of a method saving a user document, and all you want to obtain is, when things go wrong, you can tell the user the save operation failed and give some indication as to what caused that. Then you might do a simple catch(Exception exc) and communicate the problem.
OTOH if you're going to try and resolve several possible problems, each in their own way, you would need to have separate catch blocks. Whether they go with a common or several separate try blocks again is your choice.
BTW: Coincidentally I'm in the middle of writing a little article on exception handling right now!
|
|
|
|
|
Haha, I'll check the article out when it's up if you'll post a link.
I typically just want to tell the user that a failure occurred. But I also want to specify WHY it occurred. (eg. "You do not have permission to access this file.", from catching "UnauthorizedAccessException"). Should I avoid trying to provide the reason and just display a message that an error occurred? And maybe log the details to a file?
|
|
|
|
|
Matt U. wrote: "You do not have permission to access this file.", from catching "UnauthorizedAccessException
You do have one thing right. Always create user friendly error messages! Nothing annoys a user more than this message: "An error has occurred." Oh wow! What useful information! For all we know, a virus has just invaded our system.
If you handle most of the validation, you shouldn't have to worry about try/catch nesting because there won't be many more actions that can be executed.
Cheers!
Richard
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
IMO you need to provide:
1. a user-friendly message that uses terms in the application domain (e.g. "save document has failed") so the user knows exactly what part of his actions did/did not succeed.
2. an indication of the kind of problem; this could be the Message part of the exception itself ("disk full").
3. if possible, a dialog that offers some choices, such as "try again", "choose another destination", ...
4. the full Exception.ToString() in a time-stamped log file (for administration/development purposes).
A useful feature is exception nesting: when a low-level exception is caugt, you could throw a higher-level exception (closer to the application domain) and include the low-level exception as a nested exception.
BTW: all my articles are reachable through the "My Articles" widget below.
|
|
|
|
|
Alright, thanks a lot. That helps me to understand the concept even more. I can't think of any other questions right now but if I do I'll be back. Thanks Luc and Richard.
|
|
|
|
|
Yes.
(Wrap the different operations in separate try/catch blocks. Perhaps in separate methods. But also do what you have there as necessary. And do any pre-validation you can.)
|
|
|
|
|
Matt U. wrote: However, is that the best way to do it?
I'd add a finally clause as a single placeholder for cleanup code.
/ravi
|
|
|
|
|
So I'm a programmer who's been programming for 20 years. I have written Windows services numerous times and need to do it again. There are things that my service code doesn't do (like run in console mode) that I'd like it to do.
So does anybody have any code that I can steal that is the basis for a Windows service? I know I can create a new project as a Windows Service through VS2010 but was wondering if anybody has a basis I can use.
Also - the premise I used was in the OnStart command, start a timer that would run a routine that would poll for things to do. The routine would never end and check, based on time, if something needs to be done. Is this still an appropriate method for doing a service or is there a better way?
TIA - Jeff.
|
|
|
|
|
Jeff - when I create a service, I tend to use a form of background thread to run the processing. If I have something that I need to run periodically, I use a Monitor because I use the Wait method for the period of time that I want the thread to sleep. This way, if I need to stop processing, I just Pulse the Monitor and shut it down.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I tend to write Services using a System.Timers.Timer -- so all I really need to do each time is write an Elapsed handler.
|
|
|
|
|
Hi all,
Please suggest me how to convert a word document to xsl/xslt (.doc file to xsl file). Please provide me some sample code or URL from where I can do this using C# 2.0 without using any third party tools.
Thanks in advance
Know is Drop, Unknown is Ocean
modified on Tuesday, July 20, 2010 9:16 AM
|
|
|
|
|
|
No, actually our requirement is to generate XSL file based on the word document (word document is an template with mail merge, later we merge data with this template document retrieved from database). We have different kind of document, for each selected document we have to create XSL file dynamically using C#.
Know is Drop, Unknown is Ocean
|
|
|
|