-
November 22nd, 2012, 06:34 AM
#1
Help With Project Please
The idea is for the program to be simple command line program.
The program basically looks in a defined directory and opens the contained HTML file in IE and then prints them. However I think from the two errors I'm getting it looks like I've over looked something, do you have any suggestions?
Ideally I'm would like the program to stay as a single Class.
My errros are:
'Bulk_Pdf.Main.Main(string)': a static constructor must be parameterless (CS0132) - C:\Users\Ben\Desktop\bulkPrint_pdf.cs:16,18
'Bulk_Pdf.Main.Main(string)': access modifiers are not allowed on static constructors (CS0515) - C:\Users\Ben\Desktop\bulkPrint_pdf.cs:16,18
Do you havee any suggestions?
Code:
using System;
using System.IO;
namespace HTML_Print
{
class Main
{
private static Main(string dirPath)
{
// Define Working Directory
DirectoryInfo dir = new DirectoryInfo(@"C:\fileDump");
// Define File Type
foreach (FileInfo finfo in dir.GetFiles("*.html"))
// Open IE Explorer and Print
if (Application.Current.Properties["finfo"] != null)
{
string fname = Application.Current.Properties["finfo"].ToString();
if (String.IsNullOrEmpty(fname))
{
fileLabel.Content = "No File Specified";
}
else
{
fileLabel.Content = fname;
SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
IE.DocumentComplete +=new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);
IE.PrintTemplateTeardown += new SHDocVw.DWebBrowserEvents2_PrintTemplateTeardownEventHandler(IE_PrintTemplateTeardown);
IE.Visible = true;
IE.Navigate2(fname);
}
}
}
void IE_PrintTemplateTeardown(object pDisp)
{
if (pDisp is SHDocVw.InternetExplorer)
{
SHDocVw.InternetExplorer IE = (SHDocVw.InternetExplorer)pDisp;
IE.Quit();
System.Environment.Exit(0);
}
}
void IE_DocumentComplete(object pDisp, ref object URL)
{
if (pDisp is SHDocVw.InternetExplorer)
{
SHDocVw.InternetExplorer IE = (SHDocVw.InternetExplorer)pDisp;
IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 2);
}
}
}
}
-
November 23rd, 2012, 04:01 AM
#2
Re: Help With Project Please
Here's a constructor definition:
Constructor()
Here's a method definition that returns something:
string Method()
Here's a method definition that returns nothing:
void Method()
So we can see that the compiler uses a logic like "if there is a word before the method/constructor name that is a Type, like 'string' or 'void' then it is a method, if there is no word (because constructors don't return anything of any type), then it is a constructor
Using this info, can you work out what's wrong with your code?
Code:
private static Main(string dirPath)
Hints:
From the error message, it's clear to see tha tthe compiler thinks your line of code above is a constructor (when it actually needs to be a method) - can you work out why
You may find your main needs a string array as a parameter
-
November 23rd, 2012, 01:40 PM
#3
Re: Help With Project Please
Any method that has the same name as the class in which it is contained is considered by the compiler to be a constructor.
Since your class does not specify any access modifiers and it's only method is static, the compiler assumes the class is also static.
Static constructors are constrained by the language specification to not have any access modifiers or parameters, this is why you are getting these errors.
A Console program is required to have a Main method as the program entry point, therefore you can't rename it. Rename your class (change it to something other than Main) and the problem will go away.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|