|
Well, have you tried to format the text of the cell as : "Item1\r\nItem2\r\nItem3\r\n"?
|
|
|
|
|
Ohh yes sorry I forgot to mention I used \r\n and Environment.NewLine (which is pretty much the same thing) with no luck.
|
|
|
|
|
Try inserting <BR> tags instead of newlines. That might do the trick.
Josh
|
|
|
|
|
Good spot (especially since its in the wrong forum)
|
|
|
|
|
Hello,
What is the procedure for printing any file (Ms Word, PDF etc) using shell within C# ?
Thanks
|
|
|
|
|
Hello, I've taken following code -as it is- from the MSDN documentation, just for the consistency, otherwise the problem is simple. For more information search in the index for "Process.StartInfo". Here you go:
void PrintDoc()
{
Process myProcess = new Process();
try
{
// Get the path that stores user documents.
string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc";
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
}
else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message +
". You do not have permission to print this file.");
}
}
}
I Hope it will work for you.
|
|
|
|
|
Thanks a lot for your time. I am grateful to you.
|
|
|
|
|
Hi,
I am using this procedure successfully, but this procedure is always promting Print Dialogue (Select Pinter Option etc), Do you know how can I print directly without showing this prompt. May be there is some extra word I must use int he Verb = "print" , right ? but I dont know details.
thanks
Emran
|
|
|
|
|
Invisible printing using shell?? It's a bit of an odd combination. I don't think it's possible, and it will be variant from a file extension to the other as each program may have this "invisible printing" - supposing it actually exists in any program at all-, while other programs may not support it!!
You see, printing using shell is just launching the program associated with this file extention with the parameter "print". Usually the program will ask for more information - Printer, quality, Color/B&W, & so on-, that's why it shows the dialogue.
I'll dig up for more info, but -I'm sorry- I can't promise you anything. If you want to print few known popular document types -like you said yourself, pds MS Word-, why don't you put it in your program as a component, and print it using the component if possible? (just an idea )
|
|
|
|
|
Hello,
I appreciate your response.
I am just willing to print HTML files invisibly. And I did not understand about putting that in my program as component. Would you please explain me about component printing. (specially for HTML files).
Thanks
Emran
|
|
|
|
|
Well, it's quite simple. For eaxmple if you wish to print HTML pages whether online or on your computer. you implement a WebBrowser component (Whether visible = true, or false, it doesn't matter). Then you use:
webBrowser1.Print();
You don't need to make it visible as I said. you can put it there invisible just for printing, or you can use its full capabilities.
to change the URL use the Navigate() method.
but it's IMPORTANT to make sure that all default print setting are valid. For example make sure that your current printer is connected, On, and set as default, or you may end up printing that page using adobe virtual pdf printer, or even printing it to a file (according to your default printing settings). Also default Color options (Color - Grey Scale - B&W) are used without a choice. That's how you print invisibly;
I hope this was useful... Good Luck.
|
|
|
|
|
Thanks for the idea.
|
|
|
|
|
Hi Nader,
I have a big problem about SQL and I posted my question, but did not get right reply. So, rather than reposting, I thought If I ask you, you may help me about it. I do believe that, the solution of my problem is really very simple, but I just dont know and never found yet.
My Question: I am using SQL Express 2005 for my windows application (.NEt 2.0 C#). I made different copies of the application in different folders along with .mdf files. I wanted to treat each .mdf as an independent seperate file only accessible by the application of the same folder or only the instance of the application which has defined the connection string for the particular mdf. But every time I change some value of any one instance of the .mdf file from applications in different folders, all .mdf files are being synchronized. Now Its a headache for me, because I am using one copy of the application which is accessing my confidential data in .mdf file and I am also trying to make an installer to ship the application with .mdf. I dont want to ship my confidential data, and If I want to ship an emptied .mdf then I will have to delete all my data which I dont want. What is the solution for that ? Do I need to change all connection string 's "user instance = false " , I am afraid If my sql database gets messed up for that....
I will greatly appreciate your reply.
regards
Emran
|
|
|
|
|
Hello
Well, It's a kind of a strange problem. I've just finished programming an SQL client/server app, myself few days ago. In my program also there are many clients each Has his own database but your problem never occured to me??
Well, we will go through this step by step, to find out your bug.
First:
Your connection string should look like this:
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DataFile.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
What you should do:
1) If you use the wizard to add the database right click on the project name in the solution explorer and check the "settings" tab, which is to the lower left of your screen. Check the connection string and see if it looks something like the above.
2) Revise your connection string and compare it to the one above
3) Check if your database file is copied in your directory and check it's modified date after you make modification, also check if the "Copy to output directory" is set to true.
You MUST add the database file to your project and make sure that the "Copy to output directory" is set to true, so that also your deployment project adds the file automatically.
Finally, my guess is:
Actually your Apps are never able to "synchronize" data. The connection string allows each app to connect to one database file only, until you close the connection first and reopen it again using the same or another string. Yes it's called "disconnected" database access, but there is no common relation between your apps, & synchronization must be done intentionaly.
The only way that your applications are all connected to one database file, and by the way it's propably the main database file in your project folder (or wherever you've put it). So try to rename the Main empty database file to something else (ofcouse visual studio must be closed first). then try to run one of your apps. If it gives you an exception when it connects to its database, then that means that it tried to connect to tha main database file, and all your apps do the same. So they are all modifying one database file.
If this happens check your connection string.
If you need more help & the above didn't solve it, I'm waiting for your post, but please put your connection string in it.
Good luck. need more help. I'm waiting for your post, but please but your connection string in it.
Good luck.
|
|
|
|
|
Hello Nader Elshehabi,
I am extremely sorry for not replying you in time. I could not get a chance to reply in last 2 days. I have gone thru your suggessions and I have checked the connection string. I found that, connection string was showing absolute path to a single database file rather than dynamically getting the folder name. So, I fixed the path and now it is working excellent. I appreciate your co-operation.
But I was shocked when I found a problem
I have made a installer of My Windows Application (C# 2005 Express) and ported my software to a different computer. my installer installes SQL Server 2005 Express in the target machine at first then copy my software. When I installed the software in that computer and I clicked to run, I got the following error message and Program shut down.
.........................................................................
An error has occured while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the fact
that under the default settings SQL Server does not allow remote
connections. (Provider: SQL Netowrk Interfaces, error:26 - Error locating
Server/Instance specified.)
..........................................................................
Would you please guide me about this problem. Why it is looking for remote connection, It is not something like ASP.NET connecting thru Website or something like that. it is the very mdf file which is already available in the same PC and it should be accesssible thru the connection string I programmed in the application, right ?
Thanks and regards
Emran
|
|
|
|
|
I'm sorry I've replied Late, but I hope not too late.
This message appears when there is no connection between your application and SQL server. Not necessarily across a network. You must have realized that you need SQLExpress installed on the user's computer for your application to work. So your deployment project must include an install option to install SQLExpress Before installing your application. To do this, follow these steps:
1- Right click on the name of your deployment project in the Solution explorer
2- Click on the properties
3- Click on the "Prerequisites" Button.
4- Check the check box on top if this dialog, it should say "Create setup program to intstall..."
5- Now, in the list check on
a) Microsoft Data access components
b) .Net framework
c) Windows Installer
d) SQL server 2006 Express Edition
6- You should see three radio buttons in the lower part of the dialog. Check the meddle one.
Now pree OK and SQL express will be installed with your application Only if it's not already installed on the target computer. Notice that It will NOT be uninstalled after uninstalling your application. To do this you have to put it in the custom actions of your setup program.
This will work only if you have Visual Studio 2005. Steps on older versions are more complicated. If this doesn't work for any reason, I'm here for your next post.
|
|
|
|
|
Hi Nader,
Thanks a lot. As I am using Express Editon of C# .Net 2005, I dont have any Setup making feature in my IDE. But I fix my 3rd party installer so that SQL Server is installed. After installing SQL Server, every thing is running ok Now.
One problem I was trying to figure out for a long time.
It is, So many times, When My application try to loads, it takes time and before it loads, Exception is thrown "Timeout Expired". I guessed, this timeout is SQL Server's connection timeout. So, In my config file, I changed the connection time out from 15 seconds to 120 seconds (high enough to get rid of this error), yet, IT looks like, the timeout value is stored in some other place where the value is so low, most of the time, time out expires. Some of my user may have slow computer and all the time they will face this Timeout expire error. Would you please give me a clue about it.
Thanks for your time. I am keep on asking you question, I felt for your time, Insallah Once this Timeout problem is solve, I hope not to bother you again.
Thanks and regards
Emran.
|
|
|
|
|
Dear Emran, I'm realy happy to help you, please don't be so sensitive, you're NOT bothering me at all.
For the loading problem, I feel it's not the SQL timeout, I really doubt it. Do you make any other connections? like using sockets? any other procuders that uses timeout, like browser component?, try to debug your application to that timeout exception, and trace its source. You should make sure that it's SQL timeout before tapering with the connectionstring. Also you said that the old value is 15 seconds. Does your application throws that exception after 15 seconds of loading, or more? or less?? Such answers may help you identifying the source of the exception.
Anyway, if you want to change the Timeout of your connection, don't do it directly from your application's config file, as it changes by building your app. Do it by changing the connection string as follows:
1- Right click on the project's name in the solution explorer.
2- Click on properties
3- Click on the settings tab (located to the left usually)
4- You should see your connection string to the right. When you click on it, a small button with three dtos on it "..." should appear at the right end of the field, click on that button.
5- On the dialog that shows up click on "Advanced" button
6- A property page should appear. Shearch for the timeout property and change it to the value that suits you.
If that solves your problem, then thank God, but if not, try to post me more of your loading code in your constructor and FRAME_LOAD event handler. Also post the Call stack of your exception, so that we could trace the source of the timeout, as I'm not convinced that the problem is in the SQL timeout.
If you have ANY question at ANY time, don't think twice. Post it, or even send it to me as an email, OK?;) I'm waiting for your reply to see if this works out.
|
|
|
|
|
I got a String returned from Database which has 3 lines, like "Test1\n Test2 \n Test3", but it showed in C# TextBox as "Test1 Test2 Test3". It seems C# TextBox can't preserve the line feed character. How can I make it show in TextBox as 3 lines?
Thanks
TinaQ
-- modified at 18:57 Tuesday 16th May, 2006
|
|
|
|
|
1. Make sure your TextBox 's Multiline property is true .
2. TextBox es don't like "\n". Use String.Replace("\n", "\r\n") on the data to give it the CRLF newlines it likes.
--
I've killed again, haven't I?
|
|
|
|
|
You should replace the \n with Environment.NewLine rather than hard coding \r\n
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks a lot, Everyone! Now it worked.
-- modified at 20:06 Tuesday 16th May, 2006
|
|
|
|
|
If you insert Environment.NewLine and Multiline is true, the text will show as multiline. If not, post your code.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Now it worked, sorry it's my mistake before. Thanks a lot!!!
|
|
|
|
|
Does anyone know how to stop a service form being killed by the Task Manager or any other method other than the services own stop function.
If this is at all possible?
Cheers
|
|
|
|
|