Wednesday, October 16, 2013

Converting time zone in asp.net,C# and vb.net through framework 3.5.

First add below references.

Namespace:  System
Assembly:  System. Core (in System. Core. dell)

Sample function that works for all of you.

Create below function in common classes.

  Public Function GmtToPacific (ByVal dateTime As DateTime) As DateTime
        Return TimeZoneInfo. ConvertTimeFromUtc (dateTime, TimeZoneInfo. FindSystemTimeZoneById ("Pacific Standard Time"))

    End Function

Calls this function and pass input date in UTC/GMT format.

Dim objName as new CommonClassName

objName .GmtToPacific(sinceDate.ToUniversalTime.ToString())


How to consume RaaS service( Report as a service), details and sample code

Dim webRequest As HttpWebRequest = DirectCast(Net.WebRequest.Create("URL of Raas service"), HttpWebRequest)
        webRequest.Method = "GET"
        webRequest.ContentType = "application/x-www-form-urlencoded"
        webRequest.Credentials = New NetworkCredential("URL of RaaS service", "token")
        Dim httpResponse As HttpWebResponse
        Dim contentReader As StreamReader
        Try
            httpResponse = DirectCast(webRequest.GetResponse(), HttpWebResponse)
            contentReader = New StreamReader(httpResponse.GetResponseStream())
            Dim readToEnd As String = contentReader.ReadToEnd()
        Catch ex As Exception
            '' Log the exception here
        End Try

Monday, October 14, 2013

Zip facility (Zip compression) with .NET Framework

This is very simple to create a zip file and extract this through .net framework,Many developers where using third party components like DotnetZip



Zip is one of the most accepted archive file formats. Zip format is supported in almost all operating systems with some built-in name.
  • In Windows operating system it’s implemented by the name “Compressed folders”.
  • In MAC OS it’s implemented by the name “Archive utility”.
Now in .NET we did not have built-in support for implementing Zip compression. Many developers where using third party components like “DotnetZip”. In .NET 4.5, the Zip feature is baked in the framework itself, inside the namespace System.IO.Compression.
The first step is you need to reference two namespaces:
  • System.IO.Compression.FileSystem
  • System.IO.Compression
If you want to Zip files from a folder you can use the CreateFromDirectory function as shown below.
ZipFile.CreateFromDirectory(@"D:\data",@"D:\data.zip");

If you wish to unzip, you can use the ExtractToDirectory function as shown in the below code.
ZipFile.ExtractToDirectory(@"D:\data.zip", @"D:\data\unzip");

Friday, October 11, 2013

How to insert large string or xml file in the oracle database Clob field.





How to insert large string or xml file in the oracle database Clob field.
 

Solution:-

We can declare some variable and divide the large string into this.
Further while inserting the string or large file we can concentinate those variables and insert/update into database.

Sample code is
Declare
  str1 varchar2(4000);
  str2 varchar2(4000);
  str3 varchar2(4000);
  str4 varchar2(4000);

begin                                                                    
  str1 := 'Test data';                                                                                                             
  str2 := 'Test data';
  str3 := ' Test date';
  str4 := ' Test data';   
 
update TableName set coloumName = to_clob(str1) || to_clob(str2) || to_clob(str3) || to_clob(str4)

commit;

Some date format mostly using for UTC time zone, VB.NET and C#.


yyyy-MM-ddTHH:mm:ss.000
yyyy-MM-ddTHH:mm:ssZ

Date.ToString("yyyy-MM-ddTHH:mm:ssZ")
Format(Date., "yyyy-MM-ddTHH:mm:ss.000")


Handle special character in oracle while inserting and updating.



Most of the time we are facing problem while inserting or updating special character in oracle database.

when executing the scripts it gives/ask to insert values for those fields which followed by special signature like "&"

How to insert special character in database ??



How to use ||chr(38) || in oracle ??
 

Solution is :-



In the query just replace "&" with ||chr(38) || and this will work