Friday

C# csharp read from file write into file


public static string ReadFile(string f){
System.IO.StreamReader file = new System.IO.StreamReader(f);
string testxmldata = file.ReadToEnd(); file.Close();
return testxmldata;
}
public void WriteIntoFile(string path,string m) {
if (!File.Exists(path)) {
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path)) {
sw.WriteLine(m);
}
}
else {
// This text is always added, making the file longer over time
// if it is not deleted.
using (StreamWriter sw = File.AppendText(path)) {
sw.WriteLine(m);
}
}
}

more...

Thursday

remove bing from internet explorer

Go to this page and setup different provider (google for example):
http://www.ieaddons.com/en/searchproviders

In internet explorer menu open Tools/Manage addons /Search providers
Right click on Bing, then select remove from popup menu.

more...

Tuesday

Passing NULL values to SqlCommand.Parameters.AddWithValue

this code might help
       
SqlCommand sqlCmd = new SqlCommand(sqlStatment, dbConn);
sqlCmd.Parameters.AddWithValue("@Name", name);
sqlCmd.Parameters.AddWithValue("@Surname", surname);
foreach (SqlParameter Parameter in sqlCmd.Parameters)
{
if (Parameter.Value == null)
{
Parameter.Value = DBNull.Value;
}
}

more...

Friday

The wave header is corrupt fix Or how to play wav file with System.Media.SoundPlayer in dot.Net C#

1.add this MediaPlayer class
class MediaPlayer
{
System.Media.SoundPlayer soundPlayer;
public MediaPlayer(byte[] buffer)
{
MemoryStream memoryStream = new MemoryStream(buffer, true);
soundPlayer = new System.Media.SoundPlayer(memoryStream);
}
public void Play() {soundPlayer.Play();}
public void Play(byte[] buffer)
{
soundPlayer.Stream.Seek(0, SeekOrigin.Begin);
soundPlayer.Stream.Write(buffer, 0, buffer.Length);
soundPlayer.Play();
}
}

2. Then file playing procedure will be looking like this:
private void PlayMyFile()
{
string file1 = @"c:\sample.wav";
List<byte> soundBytes = new List<byte>(File.ReadAllBytes(file1));
//create media player loading the first half of the sound file
MediaPlayer mPlayer = new MediaPlayer(soundBytes.ToArray());
//begin playing the file
mPlayer.Play();
}

more...

Thursday

C# generic list copy with constructor

     
using System;
using System.Collections;
using System.Collections.Generic;
namespace Business.Web.Models {
public class DtoMapper {
// this is generic method replacing non-generic metod
// InvoiceDto_OLD provided in source below
public List<T2> Transform<T1,T2>(List<T1> i, Func<T1,T2> del)
{
List<T2> ret = new List<T2>();

foreach (T1 val in i) {
ret.Add(del(val));
}
return ret;
}

// generic method can be called as follows:
public List<InvoiceDto> InvoiceDto(List<Invoice> i) {
return Transform<Invoice,InvoiceDto> (i.ToList(),l=>new InvoiceDto(l));
}

// this is sample of old non-generic method
public List<InvoiceDto> InvoiceDto_OLD(List<Invoice> i) {
List<InvoiceDto> ret = new List<InvoiceDto>();

foreach (Invoice invoice in i) {
ret.Add(new InvoiceDto(invoice) );
}
return ret;
}
}
}

more...

Tuesday

view GAC, add dll to GAC


to view registred dlls in GAC open this folder in explorer:
C:\WINDOWS\assembly

To Register GAC , use following command:
c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe /i [mydll]
more...

Saturday

To analyze website with FxCop

Open FxCop click newProject/AddTargets and find your website compiled here:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\[yourwebsitename]
Press Ctrl+A and add all dlls.

more...

open web page in android application:

don't forget to set permission


package com.test2;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
android.webkit.WebView wv =
(android.webkit.WebView)this.findViewById(R.id.WebView01);
wv.loadUrl("http://sourcefield.blogspot.com");
}
}

Could not load file or assembly Microsoft.ReportViewer.WebForms:

usually it's located into c:\Program Files\Microsoft Visual Studio 9.0\ReportViewer\

For visual Studio 2005 run this installer to add this to GAC:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\ReportViewer\ReportViewer.exe
more...

Thursday

fix:android.webkit.WebView

In order to allow WebView to display pages,android.permission.INTERNET permission has to be added :

<uses-permission android:name="android.permission.INTERNET"></uses-permission>


Can also be edited graphically in Eclipse plugin through permissions tab.

Monday

AutoHotkey autoplayer for Online games

Here is auto-click script for 'point and click' games , you will need AutoHotkey and save this as .ahk file .

SetKeyDelay, 75, 75
;Exits AutoHotKey application.
$^CapsLock::
ExitApp
return
;Pauses AutoHotKey Script.
F6::Pause, Toggle, 1
$x::
Loop {
MouseClick
sleep 10
}

more...

C# source to find XML tag recursively


 [TestFixture]
public class test
{
[Test]
public void XPathTest()
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\LinqObjects.xsd");

foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
ProcesNode(node, doc.DocumentElement.Name);
}
}



private void ProcesNode(XmlNode node, string parentPath)
{
if (!node.HasChildNodes || ((node.ChildNodes.Count == 1) && (node.FirstChild is System.Xml.XmlText)))
{
if (node.Name == "Parameter")
{
//System.Diagnostics.Debug.WriteLine(parentPath + "/" + node.Name);
}
}
else
{
foreach (XmlNode child in node.ChildNodes)
{
ProcesNode(child, parentPath + "/" + node.Name);
}
}
}
}

more...

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...