Pages

May 26, 2011

How to insert a Guid or UniqueIdentifier and return it as a OUTPUT parameter + StoredProcedure. + SQL


CREATE PROCEDURE [test]
    @name as varchar(50),
    @id as uniqueidentifier OUTPUTAS
BEGIN
    declare @returnid table (id uniqueidentifier)

    INSERT INTO test(
        name
    )
    output inserted.id into @returnid
    VALUES(
        @name
    )

    select @id = r.id from @returnid rEND
Above SP returns the newly inserted GUID as the OUT parameter.

May 20, 2011

How to use double coute in string + C#

This usage of double coutes in a string can be easily done using @.
For eg:
To show the below text 
 "This is a "Test"


Code:
TextBox1.text = @"""This is a " + @"""Test""";


The logic is that if you use @ in front of the sting variable then using e double coute(""") 
throughout the string will give you one double coute(").

How to create a text file and save it on client machine using Save File Dialog + Asp.Net + C#

Method to Create text file:
Using System.IO;
Using SystemsText;

private void CreatetxtFile()
{
StringBuilder sb = new StringBuilder();

sb.AppendLine("test");
sb.AppendLine("= = = = = =");
sb.AppendLine();
sb.Append("test2");
sb.AppendLine();
sb.AppendLine();

using (StreamWriter outfile = new StreamWriter("c:" + @"\AllTxtFiles.txt"))
{
outfile.Write(sb.ToString());
}

}
Code to Save the file as dialog :
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename=AllTxtFiles.txt");
// specify the path of the file that has to be saved in client machine.
Response.TransmitFile("c://AllTxtFiles.txt");
Response.End();
The above code will show a save file dialog to save the file.