|
eggsovereasy wrote: Why have a method return an error code which you pass to an error code processing method when you can just throw the appropriate exception when it occurs.
Why? Obviously it's an exceptional condition.
led mike
|
|
|
|
|
Thanks for the reply. Only the thing i want to know is the best design to implement Exception\message Handling, using custom exception classes and resource files contains errors/message keys and descriptions.
Thanks
|
|
|
|
|
I represented the data in Crystal Report based on certain conditions. which is stored in a table "abc" .
I used CrystalReportViewer Control and my Crystal Report name is crystalreport1.rpt . and control name is crystalreportviewer1
I have a task to convert that report into pdf file and save into a folder(output) in Drive C: . and also to open that pdf file after creating the pdf.
My question is what will be the C# code to convert Crystal Report into pdf files and stored in that folder of drive C: .
|
|
|
|
|
I have converted this code from vb without testing, so please correct any syntax error ...
<br />
DiskFileDestinationOptions DiskOpts = New DiskFileDestinationOptions();<br />
oReport.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile;<br />
oReport.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat;<br />
DiskOpts.DiskFileName = ExportPath + requiredFilename;<br />
oReport.ExportOptions.DestinationOptions = DiskOpts;<br />
oReport.Export();<br />
crViewer.ReportSource = null;<br />
oReport.Dispose();<br />
oReport = null;<br />
<br />
Response.Clear();<br />
Response.AppendHeader("Content-Disposition", "attachment; filename=filename.pdf");<br />
Response.ContentType = "application/pdf";<br />
Response.WriteFile(ExportPath + requiredFilename);<br />
Response.End();<br />
<br />
<br />
Response.Redirect(pdffilenameandpath, true);<br />
<br />
-----
|
|
|
|
|
Is there any dll file needed to convert into PDF
|
|
|
|
|
A few statements from how I run a Crystal Report via a Windows Service:
Defile is a FileInfo indicating the RPT file.
reportfile is a FileInfo indicating the destination for the PDF.
CrystalDecisions.CrystalReports.Engine.ReportDocument crRpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument() ;
crRpt.Load ( Defile.FullName ) ;
crRpt.SetParameterValue
(
parm.Key
,
parm.Value
) ;
crRpt.ExportToDisk
(
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
,
reportfile.FullName
) ;
|
|
|
|
|
I am just learning XML and C# so I appoligize for any inconvience in advance. The program I am working on interfaces with another program that I did not write. I create a XML request for the program to do something and it responds with an XML response that tells me if it was succesful. The problem I have is parsing the response to find out if there are any errors. A basic response looks like this:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="7.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnErrror">
<CustomerAddRs statusCode="3110" statusSeverity="Error" statusMessage="The name was not valid"></CustomerAddRq>
<VendorAddRs statusCode="0" statusSeverity="None" statusMessage="Vendor succesfully added"></VendorAddRs>
</QBXMLMsgRq>
</QBXML>
The problem I have is that each of the elements could be different, as in this case, there is a VendorAddRs element and a CustomerAddRs element. I have been trying to use the XmlTextReader and XMLDoc to try and check to see if the statusCode is something other than 0.
A lot of the information I have found assumes that you know what element you are looking for. I don't care what the element is (if it's a customerAdd or a VendorAddRs) but really what the statuscode is and what the statusmessage is the code is anything other than 0.
I was thinking that I could just read through the xml and see if the node I'm at has any attributes, and if it does, check the first attibute to see if it starts with "statusCode" but that hasn't worked so far.
If there is an article or a post that someone could point me to, I'd appreciate it, as I have not had any luck finding an article that addresses this.
Thank you so much for your time.
|
|
|
|
|
If you know the attribute name you could use XPath:
XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc.Load(responseStream);
XmlNode myAttribute = myXMLDoc.SelectSingleNode("//@attributeIAmLookingFor");
This is a very good XPath tutorial.[^]
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Wow! XPath seems really usefull for XML! Thank you very much for the article!
It appears that this is what I need. Since there can be multiple elements in one document that have statusCodes, I would venture to say that I should use:
XmlNodeList myNodeList = myXMLDoc.SelectNodes("//@attributeIAmLookingFor");
foreach(XmlNode n in myNodeList)
{
// Check the value of the node 'n' to see if it != "0"
}
I'm going to do some testing on this right now and then sit down and read up on XPath some more!
Thanks again!
|
|
|
|
|
hpjchobbes wrote: Since there can be multiple elements in one document that have statusCodes, I would venture to say that I should use:
XmlNodeList myNodeList = myXMLDoc.SelectNodes("//@attributeIAmLookingFor");
foreach(XmlNode n in myNodeList)
{
// Check the value of the node 'n' to see if it != "0"
}
There you go my friend!
If your document uses XML namespaces, it can get hairy. In that case, you will have 2 choices:
1) Use the class XmlNamespaceManager in your calls to SelectNodes, if your XML document uses prefixes.
2) If it does not use prefixes, you will have to resort to fully-qualified XPath queries, like:
//@*[local-name()='attributeIAmLookingFor' and namespace-uri()='http://somenamespace.com']
This is an alternative XPath syntax. Also, from your example above, you could save some code:
//@*[local-name='attributeIAmLookingFor' and namespace-uri()='http://somenamespace.com' and number()!=0]
Have fun!
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Evening guys,
Hopefully a quick question.
I am trying to iterate all sub directories within a folder using the DirectoryInfo.GetDirectories()
This isall fine until the search hits a directory that I do not have permisions for, unfortunately at this point an UnathorisedAccessException is thrown which is perfecty understandable.
What I would like to do is retrieve a list of directories that I do have permission for and ignore any that I don't.
Any ideas?
Many thanks
Paul
ps, what event is it thrown for the enter key on a text box??
Paul
|
|
|
|
|
Hi,
the only way that works for me is by using SearchOption.TopDirectoryOnly and performing the
recursion myself, with a try-catch inside the foreach that iterates over the subdirectories at
the current nesting level.
I see no real use for SearchOption.AllDirectories because of the possible exceptions it does
not handle well.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Sounds good, many thanks
Paul
|
|
|
|
|
pprice wrote: what event is it thrown for the enter key on a text box??
handle one of the text boxes Key Events and check the event args to see if the KeyCode is Keys.Enter
|
|
|
|
|
Kinda hoped there would be a more specific event that I did not know about, ho well, many thanks anyway
Paul
|
|
|
|
|
Hi,
I have a app that i want to embed in a ASP.net page but i dont know where to start. Does anyone have any articles or info on how to go about embedding a c# control on a asp page?
Regards,
Gareth.
|
|
|
|
|
Create it as a WebControl... Windows and the web don't use the same stuff, so you'll have to wrap the functional parts of the application with web stuff.
|
|
|
|
|
Jasmine2501,
Are you saying that i would need to re-create the whole app again using WebControls?, i dont quite understand what you mean by "wrap the functional parts".
I know this is possible, as a company i worked for used to embed c# windows controls in web pages, but i never worked on how they did it.
Regards,
Gareth.
|
|
|
|
|
I found this: http://aspnet.4guysfromrolla.com/articles/052604-1.aspx[^][^]
But am having trouble displaying the control, i just get a red x.
<object id="LoginControl" height="255" width="337" classid="http:UNet.Manager.dll#UNet.Manager.Login.LoginControl"><br />
<param name="LoginControl" value="LoginControl"><br />
</param></object>
Regards,
Gareth.
|
|
|
|
|
Solved it.
Regards,
Gareth.
|
|
|
|
|
FTA:
"Hosting a Windows Control in ASP.NET has several limitations worth discussing. First it requires both that the client machines have, at minimum, the .NET redistributable installed and be browsing with Internet Explorer 5.01 or later. While this may work for a corporate intranet, it is not feasible for a public Internet application."
That makes it worthless for me. I don't like to alienate the users smart enough to use Firefox.
|
|
|
|
|
Jasmine2501,
Well since i am developing a prototype which will only ever be used by 1 person, that point isn't valid.
Regards,
Gareth.
|
|
|
|
|
I want user to enter A-Z or 0-9 only. what's wrong with this
RegularExpressions.Regex reg = new RegularExpressions.Regex("[a-zA-Z0-9]");
if i enter :hello or _hello or !hello it says it's valid but its not
if (reg.IsMatch(textfield1.Text))
{
}
Thanks for helping me out in advance
|
|
|
|
|
You need to say that it must match at the begining and end with ^ and $ and you need to allow 1 or more matches with +
^[a-zA-Z0-9]+$
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I have a class class1, which has a constructor and one method:
public class1(TextReader tr)
{
InitFromTextReader(tr);
}
protected virtual bool InitFromTextReader(TextReader tr)
{
}
It has subclass class1_1 , which also has a subclass class1_1_1 .
These two classes both override InitFromTextReader .
The text stream I am reading has class names embedded in it, just before the data for the object. So I read the class name, get the Type object for it and ask for the constructor that takes a TextReader as it's one and only parameter.
GetConstructor is not finding that constructor for the subclasses. I used GetConstructors , and it just does not exist.
So, all that to ask:
Even though they do not do a dang thing, do I need to write constructors
public class1_1(TextReader tr)
: base(tr)
{
} and
public class1_1_1(TextReader tr)
: base(tr)
{
}
so that I can find them with GetConstructor ?
It this kind of thing wot causes unrest!
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|