March 22, 2010
Command-line arguments in the C language
The C language provides a method to pass parameters to the main() function. This is typically accomplished by specifying arguments on the operating system command line (console).
The prototype for main() looks like:
int main(int argc, char *argv[])
{
…
}
There are two parameters passed to main(). The first parameter is the number of items on the command line (int argc). Each argument on the command line is separated by one or more spaces, and the operating system places each argument directly into its own null-terminated string. The second parameter passed to main() is an array of pointers to the character strings containing each argument (char *argv[]).
For example, at the command prompt:
test_prog 1 apple orange 4096.0
There are 5 items on the command line, so the operating system will set argc=5 . The parameter argv is a pointer to an array of pointers to strings of characters, such that:
argv[0] is a pointer to the string “test_prog”
argv[1] is a pointer to the string “1”
argv[2] is a pointer to the string “apple”
argv[3] is a pointer to the string “orange”
and argv[4] is a pointer to the string “4096.0”
Notes
• The main() routine can check argc to see how many arguments the user specified.
• The minimum count for argc is 1: the command line just contained the name of the invoked program with no arguments.
• The program can find out its own name as it was invoked: it is stored in the argv[0] string! Some operating systems don't provide this feature, however.
• The arguments from the command line are not automatically converted: the characters are just copied into the argv strings.
• If an argument on the command line is to be interpreted as a numerical constant, such as argv[1] and argv[4] in this example, it can be converted using a string conversion.
int int_val; float float_val;
sscanf(argv[1],”%d”,&int_val);
sscanf(argv[4],”%f”,&float_val); and
printf(“The 3rd and 4th items on the command line are %s and %s\n”, argv[2], argv[3]);
results in: The 3rd and 4th items on the command line are apple and orange
The string functions atoi(), atol(), atof(), etc., will also work.
February 15, 2010
Java Menu
friend As i commit u ppl I m giving you code of menu with action on menu
Hope so this code will help u in ur project
Prof.Prasad Sawant
/* BY
Prof.Prasad Sawant
BCA
Prof .Ramkrishana More A.C.S College */
import java.awt.*;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.ButtonGroup;
import javax.swing.JMenuBar;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
//Used Action Listner for JMenuItem & JRadioButtonMenuItem
//Used Item Listner for JCheckBoxMenuItem
public class JMenuDemo implements ActionListener, ItemListener{
JTextArea jtAreaOutput;
JScrollPane jspPane;
public JMenuBar createJMenuBar() {
JMenuBar mainMenuBar;
JMenu menu1, menu2, submenu;
JMenuItem plainTextMenuItem, textIconMenuItem, iconMenuItem, subMenuItem;
JRadioButtonMenuItem rbMenuItem;
JCheckBoxMenuItem cbMenuItem;
ImageIcon icon = createImageIcon("jmenu.jpg");
mainMenuBar = new JMenuBar();
menu1 = new JMenu("Menu 1");
menu1.setMnemonic(KeyEvent.VK_M);
mainMenuBar.add(menu1);
//Creating the MenuItems
plainTextMenuItem = new JMenuItem("Menu item with Plain Text",
KeyEvent.VK_T);
//can be done either way for assigning shortcuts
//menuItem.setMnemonic(KeyEvent.VK_T);
// Accelerators, offer keyboard shortcuts to bypass navigating the menu hierarchy.
plainTextMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_1,
ActionEvent.ALT_MASK));
plainTextMenuItem.addActionListener(this);
menu1.add(plainTextMenuItem);
textIconMenuItem = new JMenuItem("Menu Item with Text & Image", icon);
textIconMenuItem.setMnemonic(KeyEvent.VK_B);
textIconMenuItem.addActionListener(this);
menu1.add(textIconMenuItem);
//Menu Item with just an Image
iconMenuItem = new JMenuItem(icon);
iconMenuItem.setMnemonic(KeyEvent.VK_D);
iconMenuItem.addActionListener(this);
menu1.add(iconMenuItem);
menu1.addSeparator();
//Radio Button Menu items follow a seperator
ButtonGroup itemGroup = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem("Menu Item with Radio Button");
rbMenuItem.setSelected(true);
rbMenuItem.setMnemonic(KeyEvent.VK_R);
itemGroup.add(rbMenuItem);
rbMenuItem.addActionListener(this);
menu1.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem("Menu Item 2 with Radio Button");
itemGroup.add(rbMenuItem);
rbMenuItem.addActionListener(this);
menu1.add(rbMenuItem);
menu1.addSeparator();
//Radio Button Menu items follow a seperator
cbMenuItem = new JCheckBoxMenuItem("Menu Item with check box");
cbMenuItem.setMnemonic(KeyEvent.VK_C);
cbMenuItem.addItemListener(this);
menu1.add(cbMenuItem);
cbMenuItem = new JCheckBoxMenuItem("Menu Item 2 with check box");
cbMenuItem.addItemListener(this);
menu1.add(cbMenuItem);
menu1.addSeparator();
//Sub Menu follows a seperator
submenu = new JMenu("Sub Menu");
submenu.setMnemonic(KeyEvent.VK_S);
subMenuItem = new JMenuItem("Sub MenuItem 1");
subMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
ActionEvent.CTRL_MASK));
subMenuItem.addActionListener(this);
submenu.add(subMenuItem);
subMenuItem = new JMenuItem("Sub MenuItem 2");
submenu.add(subMenuItem);
subMenuItem.addActionListener(this);
menu1.add(submenu);
//Build second menu in the menu bar.
menu2 = new JMenu("Menu 2");
menu2.setMnemonic(KeyEvent.VK_N);
mainMenuBar.add(menu2);
return mainMenuBar;
}
public Container createContentPane() {
//Create the content-pane-to-be.
JPanel jplContentPane = new JPanel(new BorderLayout());
jplContentPane.setLayout(new BorderLayout());//Can do it either way to set layout
jplContentPane.setOpaque(true);
//Create a scrolled text area.
jtAreaOutput = new JTextArea(5, 30);
jtAreaOutput.setEditable(false);
jspPane = new JScrollPane(jtAreaOutput);
//Add the text area to the content pane.
jplContentPane.add(jspPane, BorderLayout.CENTER);
return jplContentPane;
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = JMenuDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find image file: " + path);
return null;
}
}
private static void createGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("JMenu Usage Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuDemo app = new JMenuDemo();
frame.setJMenuBar(app.createJMenuBar());
frame.setContentPane(app.createContentPane());
frame.setSize(500, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem)(e.getSource());
String s = "Menu Item source: " + source.getText()
+ " (an instance of " + getClassName(source) + ")";
jtAreaOutput.append(s + "\n");
jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument().getLength());
}
public void itemStateChanged(ItemEvent e) {
JMenuItem source = (JMenuItem)(e.getSource());
String s = "Menu Item source: " + source.getText()
+ " (an instance of " + getClassName(source) + ")"
+ "\n"
+ " State of check Box: "
+ ((e.getStateChange() == ItemEvent.SELECTED) ?
"selected":"unselected");
jtAreaOutput.append(s + "\n");
jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument().getLength());
}
// Returns the class name, no package info
protected String getClassName(Object o) {
String classString = o.getClass().getName();
int dotIndex = classString.lastIndexOf(".");
return classString.substring(dotIndex+1); //Returns only Class name
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createGUI();
}
});
}
}
January 22, 2010
November 15, 2008
File Length
FileUploadreport.PostedFile.ContentLength==0
November 10, 2008
Screen Bound
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
this.SetDesktopBounds(0, 0, screenWidth, screenHeight);
November 7, 2008
Use Of Resources File in asp.net
To prepare a new ASP.NET Web application to use localized values, follow these steps:
1. Create a Web application by using Visual Studio 2005. To do this, follow these steps:
a. Start Visual Studio 2005.
b. On the File menu, click Web Site.
c. Click ASP.NET Web Site, click Visual Basic in the Language list, and then click OK.
Note A new Web site is created, and the Default.aspx file is displayed in Source view.
d. To switch to Design view, click Design.
2. To display static text, add controls to the page. To do this, follow these steps:
a. In the Toolbox, double-click the Label control to add a Label control to the page.
b. Click Label.
c. In the Properties window, type Date in the Text box.
d. In the Toolbox, double-click the Label control to add a Label control to the page.
e. Arrange this control to appear under the Date label.
f. Click Label.
g. In the Properties window, type Time in the Text box.
3. To display dynamic text, add controls to the page. To do this, follow these steps:
a. In the Toolbox, double-click the Label control to add a Label control to the page.
b. Arrange this control to appear to the right of the Date label.
c. In the Toolbox, double-click the Label control to add a Label control to the page.
d. Arrange this control to appear to the right of the Time label.
e. Double-click the page, and then add the following code to the Page_Load method.
Label3.Text = Format(Now(), "H:mm")
Label4.Text = Date.Now.Date
Step 2: Generate the resource files automatically
To generate the resource files automatically, follow these steps:
1. In Solution Explorer, double-click the Default.aspx file.
Note The Default.aspx file opens in Design view.
2. On the Tools menu, click Generate Local Resources.
Note By default, a new folder that is named App_LocalResources is created. Additionally, a resource file that is named Default.aspx.resx is created. This file contains information about each Label control on the page. The values in the resource file match the values that you entered for each Label control in Design view.
3. In Solution Explorer, right-click the Default.aspx.resx file, and then click Copy.
4. In Solution Explorer, right-click the App_LocalResources folder, and then click Paste.
5. In Solution Explorer, right-click the Copy of Default.aspx.resx file, and then click Rename.
6. Type Default.aspx.es-mx.resx, and then press ENTER.
Notes
• Steps 3 through 6 create a localized resource file for the Spanish language. You can create a localized resource file by including the language and the culture between ".aspx" and ".resx" in the file name.
• To edit the localized values in various resource files, open the resource files in Visual Studio 2005, and then change the properties for each localized control.
Step 3: Test the application
To test the application, follow these steps:
1. On the Debug menu, click Start Debugging.
Note By default, Microsoft Internet Explorer starts, and the Default.aspx file of the ASP.NET Web application is displayed.
2. On the Tools menu in Internet Explorer, click Internet Options.
3. In the Internet Options dialog box, click the General tab, and then click Languages.
4. In the Language Preferences dialog box, click Add.
5. In the Add Language dialog box, click Spanish (Mexico) [es-mx], and then click OK.
6. In the Language Preferences dialog box, click Spanish (Mexico) [es-mx], click Move Up, and then click OK.
7. To close the Internet Options dialog box, click OK.
8. To view the localized content on the page by using the new language settings, click Refresh on the View menu.
Example
|
November 4, 2008
File Downloading (.pdf)in asp.net
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = AppDomain.CurrentDomain.BaseDirectory + "images\\file.pdf";
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
you can download any type of file just change the Content type
November 3, 2008
November 1, 2008
Email sending with attachment
{
temp = false;
lstrFrom ="pm8sawant@yahoo.com";
lstrTo = "sawanprasad@gmail.com";
// copy = "y@r.org"+","+"A@gmail.com" ;
System.Net.Mail.MailMessage mymail = new System.Net.Mail.MailMessage(lstrFrom, lstrTo);
mymail.IsBodyHtml = true;
mymail.Subject = "Resume";
StringBuilder MailBody = new StringBuilder();
MailBody.Append(" \n");
MailBody.Append("" + "Comments" + "
\n");
MailBody.Append("" + "Hi Info "+"
\n");
MailBody.Append("" + "This is Resume Of Candidate"+"
\n");
MailBody.Append("");
mymail.Body = MailBody.ToString();
//MailAttachment maAttach = new MailAttachment(filename);
//mymail.Attachments.Add(maAttach);
Attachment at = new Attachment(AppDomain.CurrentDomain.BaseDirectory+ "CV\\"+filename);
mymail.Attachments.Add(at);
// System.Net.Mail.MailMessage mymail = new System.Net.Mail.MailMessage(lstrFrom, lstrTo,"Inquiry", strName);
System.Net.Mail.SmtpClient mySmtp = new System.Net.Mail.SmtpClient();
mySmtp.Host = "localhost";
try
{
mySmtp.Send(mymail);
temp = true;
}
catch (Exception ex)
{
temp = false;
}
return temp;
}
Regular Expressions For Doc or Docx File
There is no perfect method to restrict the user from uploading user some malicious file. one of the better way is to use the asp's regular expression validator.
ErrorMessage="Only .doc files are
allowed!"
ValidationExpression="^(([a-zA- Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ].*))+(.doc|.DOC|.DOCX|.docx)$"
ControlToValidate="File1">
ErrorMessage="This is a required field!"
ControlToValidate="File1">
share Point
SharePoint comes with multiple site templates. This video shows how to create a SharePoint site using those templates
http://www.sharepoint-videos.com/
Adding Users to a Site
Security in SharePoint is a necessity. Learn how to add users to SharePoint sites
http://www.sharepoint-videos.com/
Adding Web Parts to a Site
Web Parts are essential to providing componentized functionality in SharePoint. Watch this video to learn how to add web parts to a SharePoint site
http://www.sharepoint-videos.com/
Introducing Document Management
Document Management is a robust feature in SharePoint. Learn the various capabilities that are offered out of the box by the document management features.
http://www.sharepoint-videos.com/
Using the Recycle Bin
Learn how the two tier Recycle Bin works in SharePoint
http://www.sharepoint-videos.com/
Alerts
Alerts can be setup on SharePoint lists, libraries or individual items to send out an email notification when a condition becomes true (ex: a document is created, uploaded, modified etc). Also, watch this video to learn how to subscribe others to alerts as well
http://www.sharepoint-videos.com/
Subscribing to List or Library RSS feeds
RSS (Real Simple Syndication) is very prevalant throughout SharePoint. Learn how to use RSS in SharePoint lists and libraries
http://www.sharepoint-videos.com/
October 31, 2008
SQL FUNCTION
SQL Function
To Check Version of SQL Server through Query
Select @@Version
[http://www.1keydata.com/sql/sql-substring.html]
1] Concatenate
Sometimes it is necessary to combine together (concatenate) the results from several different fields. Each database provides a way to do this:
MySQL: CONCAT()
Oracle: CONCAT(), ||
SQL Server: +
The syntax for CONCAT() is as follows:
CONCAT (str1, str2, str3 ...): Concatenate str1, str2, str3, and any other strings together. Please note the Oracle CONCAT() function only allows two arguments -- only two strings can be put together at a time using this function. However, it is possible to concatenate more than two strings at a time in Oracle using '||'.
MySQL/Oracle:
SELECT CONCAT(region_name,store_name) FROM Geography
WHERE store_name = 'Boston';
Result:
'EastBoston'
Example 2:
Oracle:
SELECT region_name || ' ' || store_name FROM Geography
WHERE store_name = 'Boston';
Result:
'East Boston'
Example 3:
SQL Server:
SELECT region_name + ' ' + store_name FROM Geography
WHERE store_name = 'Boston';
Result:
'East Boston'
2] Substring
The Substring function in SQL is used to grab a portion of the stored data. This function is called differently for the different databases:
MySQL: SUBSTR(), SUBSTRING()
Oracle: SUBSTR()
SQL Server: SUBSTRING()
The most frequent uses are as follows (we will use SUBSTR() here):
SUBSTR(str,pos): Select all characters from
SUBSTR(str,pos,len): Starting with the
Example 1:
SELECT SUBSTR(store_name, 3)
FROM Geography
WHERE store_name = 'Los Angeles';
Result:
's Angeles'
Example 2:
SELECT SUBSTR(store_name,2,4)
FROM Geography
WHERE store_name = 'San Diego';
Result:
'an D'
3] TRIM
The TRIM function in SQL is used to remove specified prefix or suffix from a string. The most common pattern being removed is white spaces. This function is called differently in different databases:
- MySQL: TRIM(), RTRIM(), LTRIM()
- Oracle: RTRIM(), LTRIM()
- SQL Server: RTRIM(), LTRIM()
The syntax for these trim functions are:
TRIM ([[LOCATION] [remstr] FROM ] str): [LOCATION] can be either LEADING, TRAILING, or BOTH. This function gets rid of the [remstr] pattern from either the beginning of the string or the end of the string, or both. If no [remstr] is specified, white spaces are removed.
LTRIM(str): Removes all white spaces from the beginning of the string.
RTRIM(str): Removes all white spaces at the end of the string.
Example 1:
SELECT TRIM(' Sample ');
Result:
'Sample'
Example 2:
SELECT LTRIM(' Sample ');
Result:
'Sample '
Example 3:
SELECT RTRIM(' Sample ');
Result:
' Sample'
To get email Id in one column
Select EmailId from tbl_CharitableEmails union Select User_EmailId from tbl_User_Login