How to create file and read/write Data in iphone/ipad

//Documents Directory Path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//Give file Name With Extention to create
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@”FileName.docx”];
[[NSFileManager defaultManager] createFileAtPath:savedImagePath contents:nil attributes:nil];
NSFileHandle* pfile = [NSFileHandle fileHandleForWritingAtPath:savedImagePath];

//Enter Your Data
NSString *String = [NSString stringWithString:@”Your Data”];
const char *utfString = [String UTF8String];
NSData *dt = [NSData dataWithBytes:utfString length:strlen(utfString)];

//Write Data to file
[pfile writeData:dt];

//Read file Data
NSError *error = nil;
NSString *str = [NSString stringWithContentsOfFile:savedImagePath encoding:NSUTF8StringEncoding error:&error];
NSLog(@”Your Data From File : %@”,str);

How to work with Excel (.xls) files in C#.NET?

1. Add reference to COM object Microsoft.Office.Excel 12.0 or any other available library.

2. Code:

using Microsoft.Office.Interop.Excel;

private void anyfunction()
{
   Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();

   Microsoft.Office.Interop.Excel.Workbook xlWkb = null;

   Microsoft.Office.Interop.Excel.Worksheet xlWks = null;

   xlWkb = xlapp.Workbooks.Open(System.Windows.Forms.Application.StartupPath + @”Report.xls”, Missing.Value, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
   xlWks = (Microsoft.Office.Interop.Excel.Worksheet)xlWkb.Worksheets[1];

   //Sample Statement to work on sheets
   xlWks.get_Range(“A2”, “H65000”).ClearContents();

   xlWkb.Close(true, Missing.Value, Missing.Value);
}

Servlet Lifecycle

Hi friends,  in this post we will take an overview of servlet lifecycle.

First of all lets just know what is  servlet?

Servlet is a java program which runs on server side. Servlet interacts with the client via request-response. It is nothing but HTML code embedded into java code.

When any servlet get called container first checks that whether the object of requested servlet is already exists, if not then container instantiates the object and then servlet lifecycle starts with call to init method.

init() – This method gets called only once in lifecycle of the servlet. We can override this method to write the code which we want to execute only once. Object of ServletConfig is passed to this method, which contains the configuration/initialization values stated in web.xml

service() – This method gets called by the container whenever any request comes from the client for that servlet. In this method ServletRequest and ServletResponse objects are passed as arguments to this method. ServletRequest object contains the request from the client.

destroy() – It is called by the server when any servlet is no longer necessary or want to keep the servlet out of service. Container calls this method before removing the object of the servlet.

Thats how servlet lifecycle works.

Happy Coding……..!

How to make an AI Enemy Car in which it follows the track during the Race ?

The AI for enemy car can be done by using waypoints method..

the following code is used

var waypoint : Transform[];

var speed : float =20;

private var currentWaypoint : int;

var loop : boolean = true;

function Awake()

{waypoint[0]=transform;}

function Update ()

{ if(currentWaypoint < waypoint.Length)

{ var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target-transform.position;

var velocity = rigidbody.velocity;

if(moveDirection.magnitude<1)

{ currentWaypoint++;}

else { velocity = moveDirection.normalized * speed;  //velocity = Vector3.forward * speed; }  }

else { if(loop)  {  currentWaypoint=0; }

else   { velocity = Vector3.zero; }

} rigidbody.velocity = velocity;

}

 

How to move the image on touch in android


image.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams1 = (RelativeLayout.LayoutParams) image.getLayoutParams();

switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
break;

case MotionEvent.ACTION_UP:
x_cord = (int) event.getRawX();
if (x_cord la.getWidth()) {
x_cord= la.getWidth();
if(isCouponbuttonscroll==false){
isCouponbuttonscroll=true;
showDialog();
}
}
if (x_cord <windowwidth-la.getWidth()) {
x_cord =windowwidth-la.getWidth();
}
layoutParams1.leftMargin = x_cord -(image.getWidth()+0);
image.setLayoutParams(layoutParams1);
image.bringToFront();
image.setPadding(5, 5, 5, 5);

break;
}
return true;
}
});

How to pick music file from music library in iPhone application

Like UIImagePickerView to pick image from image gallery we can also pick up any music file from the music gallery of the device and can use it in our application with the help of MPMediaPickerController.

For that you need to add AVFoundation framework in your application. also to play the picked file we need to add MediaPlayer framework. and to use them just import them in respective view controller. Also in .h file you have to add MPMediaPickerControllerDelegate.

In button click action  write the following

MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

picker.delegate = self;

picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController: picker animated: YES];

This will present a controller from where we will be able to access the device’s music library. Also to get the picked file override the delegate method

– (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {

// Dismiss the media item picker.

[self dismissModalViewControllerAnimated: YES];

MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0];

NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

[self dismissModalViewControllerAnimated: YES];

// Play the item using MPMusicPlayer

MPMusicPlayerController* appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];

[appMusicPlayer setQueueWithItemCollection:mediaItemCollection];

[appMusicPlayer play];

AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];

AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];

[player play];

}

Done. Now you can play any music file from device music library into your application.

Happy Coding…..!

 

Custom Fonts in Blackberry Application

Download the .ttf (True Type Font)file and include it in src folder.

Include this code into the constructor.

EditField edField1 = new EditField (“”, “TestEditField”, 30, EditField.READONLY| EditField.FIELD_VCENTER){
protected void layout(int width, int height)
{
super.layout(customWidth, customHeight);
setExtent(customWidth, customHeight);
}
};

Font fo3 = loadCustomFonts(“digital-7.ttf”, “ThirdFont”, 0, 40);
edField1.setFont(fo3);

 

Include this function.

public Font loadCustomFonts (String path, String fontname,int fontStyle, int fontSize){
InputStream stream = this.getClass().getResourceAsStream(path);
if (FontManager.getInstance().load(stream, fontname,                 FontManager.APPLICATION_FONT) == FontManager.SUCCESS){
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
else {
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
return null;
}

By Using this we can add custom font into our Application.

thank you.

How to get parameters passed to a URL in salesforce apex

If we pass parameter while creating a page in salesforce apex like this

public PageReference setParameter()

{

public papageReference ref = new PageReference(‘/apex/print?email=’ + textEmail1);    ref.setRedirect(true);

return ref;

}

where email is the parameter. Then using the following function we can get the value of the parameter passed

public getParameter()

{

email = ApexPages.currentPage().getParameters().get(’email’);

}