Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
GeneralRe: bypass outlook security message "A programm is trying to access... " Pin
_T("No name")7-Jan-10 18:31
_T("No name")7-Jan-10 18:31 
GeneralRe: bypass outlook security message "A programm is trying to access... " Pin
Dave Kreskowiak8-Jan-10 1:24
mveDave Kreskowiak8-Jan-10 1:24 
Questioncall Crystal Report problem? [modified] Pin
miss YY6-Jan-10 15:16
miss YY6-Jan-10 15:16 
AnswerRe: call Crystal Report problem? Pin
carlecomm6-Jan-10 19:08
carlecomm6-Jan-10 19:08 
GeneralRe: call Crystal Report problem? Pin
miss YY6-Jan-10 19:14
miss YY6-Jan-10 19:14 
Questionhow to detect which encoding a file is already saved as Pin
califgal6-Jan-10 14:25
califgal6-Jan-10 14:25 
AnswerRe: how to detect which encoding a file is already saved as Pin
Luc Pattyn6-Jan-10 15:04
sitebuilderLuc Pattyn6-Jan-10 15:04 
AnswerRe: how to detect which encoding a file is already saved as Pin
carlecomm6-Jan-10 19:10
carlecomm6-Jan-10 19:10 
hi, the following code may help you.
System.Text.Encoding enc = null;
using (System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (file.CanSeek) { byte[] bom = new byte[4]; // Get the byte-order mark, if there is one
file.Read(bom, 0, 4);

if(bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf)
{
enc = System.Text.Encoding.UTF8;
}
else if (bom[0] == 0xff && bom[1] == 0xfe)
{
// ucs-2le, ucs-4le, and ucs-16le
enc=System.Text.Encoding.Unicode;
}
else if(bom[0] == 0xfe && bom[1] == 0xff)
{
// utf-16 and ucs-2
enc=System.Text.Encoding.BigEndianUnicode;
}
else if(bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff)
{
// ucs-4
enc = System.Text.Encoding.UTF32;
}
else
{
enc = System.Text.Encoding.ASCII;
}
}
else
{
// The file cannot be randomly accessed, so you need to decide what to set the default to
// based on the data provided. If you're expecting data from a lot of older applications,
// default your encoding to Encoding.ASCII. If you're expecting data from a lot of newer
// applications, default your encoding to Encoding.Unicode. Also, since binary files are
// single byte-based, so you will want to use Encoding.ASCII, even though you'll probably
// never need to use the encoding then since the Encoding classes are really meant to get
// strings from the byte array that is the file.
enc = System.Text.Encoding.ASCII;
}
return enc;
}

best wishes.

modified 27-May-14 4:59am.

QuestionRe: how to detect which encoding a file is already saved as Pin
califgal8-Jan-10 7:47
califgal8-Jan-10 7:47 
QuestionProblem with the DataGrid Control Pin
Doltsche6-Jan-10 9:51
Doltsche6-Jan-10 9:51 
AnswerRe: Problem with the DataGrid Control Pin
Saksida Bojan6-Jan-10 10:00
Saksida Bojan6-Jan-10 10:00 
GeneralRe: Problem with the DataGrid Control Pin
Doltsche6-Jan-10 11:01
Doltsche6-Jan-10 11:01 
GeneralRe: Problem with the DataGrid Control Pin
Saksida Bojan6-Jan-10 19:28
Saksida Bojan6-Jan-10 19:28 
QuestionException when trying to write in a open Excel file Pin
Priya Prk6-Jan-10 9:03
Priya Prk6-Jan-10 9:03 
AnswerRe: Exception when trying to write in a open Excel file Pin
EliottA6-Jan-10 9:08
EliottA6-Jan-10 9:08 
AnswerRe: Exception when trying to write in a open Excel file Pin
Saksida Bojan6-Jan-10 10:06
Saksida Bojan6-Jan-10 10:06 
AnswerRe: Exception when trying to write in a open Excel file Pin
Dave Kreskowiak6-Jan-10 10:22
mveDave Kreskowiak6-Jan-10 10:22 
QuestionHow use sdf Pin
SajjadZare6-Jan-10 8:51
SajjadZare6-Jan-10 8:51 
AnswerRe: How use sdf Pin
Dimitri Witkowski6-Jan-10 8:55
Dimitri Witkowski6-Jan-10 8:55 
GeneralRe: How use sdf Pin
SajjadZare6-Jan-10 16:53
SajjadZare6-Jan-10 16:53 
GeneralRe: How use sdf Pin
Dimitri Witkowski6-Jan-10 22:12
Dimitri Witkowski6-Jan-10 22:12 
QuestionSubscribing to System Events Pin
bovus6-Jan-10 5:26
bovus6-Jan-10 5:26 
AnswerRe: Subscribing to System Events Pin
bovus6-Jan-10 5:39
bovus6-Jan-10 5:39 
Questioncomponent for datagridview Pin
SajjadZare6-Jan-10 5:14
SajjadZare6-Jan-10 5:14 
AnswerRe: component for datagridview Pin
dan!sh 6-Jan-10 5:34
professional dan!sh 6-Jan-10 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.