Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
QuestionCommunication With ports in Visual.NET Pin
samira forooghi18-Sep-05 18:45
samira forooghi18-Sep-05 18:45 
AnswerRe: Communication With ports in Visual.NET Pin
zon_cpp19-Sep-05 6:08
zon_cpp19-Sep-05 6:08 
AnswerRe: Communication With ports in Visual.NET Pin
zon_cpp19-Sep-05 6:08
zon_cpp19-Sep-05 6:08 
QuestionSimple Database Problem Pin
18-Sep-05 16:57
suss18-Sep-05 16:57 
AnswerRe: Simple Database Problem Pin
KaptinKrunch18-Sep-05 17:12
KaptinKrunch18-Sep-05 17:12 
AnswerRe: Simple Database Problem Pin
KaptinKrunch18-Sep-05 17:14
KaptinKrunch18-Sep-05 17:14 
AnswerRe: Simple Database Problem Pin
FusionCoding19-Sep-05 3:20
FusionCoding19-Sep-05 3:20 
Questiongetting file bytesize Pin
g00fyman18-Sep-05 16:40
g00fyman18-Sep-05 16:40 
hi to all,

i am trying to get the bytes size of a file so i can display in statusbar, also updated as typed.

i first tried getting the encoding of the file and using getbytes() of the encoder, but it didnt come up the same as Windowx Explorer, then i tried just to get the char count and multiply * 2 but it still not work.

how is this acheived ?

this is my encoder attempt
<br />
string byteSuffix = "B";<br />
<br />
      // update file size panel<br />
      string text = this.context.Text;<br />
      if(text == null) text = "";<br />
       <br />
      byte[] bytes = this.encoder.GetBytes(text);<br />
      <br />
      double size = bytes.LongLength;<br />
      <br />
      string adjustedSize = "0.0";<br />
      string byteSize = "0.0";  <br />
<br />
      // gb<br />
      if(size >= 1000000000)<br />
      {<br />
        byteSuffix = "GB";<br />
        byteSize = size + "";       <br />
        size = size / Math.Pow(2, 30); <br />
        adjustedSize = size.ToString("N2");        <br />
      }<br />
        // mb<br />
      else if(size >= 1000000)<br />
      {<br />
        byteSuffix = "MB";   <br />
        byteSize = size + "";     <br />
        size = size / Math.Pow(2, 20); <br />
        adjustedSize = size.ToString("N2");<br />
      }<br />
        // kb<br />
      else if(size >= 1000)<br />
      {<br />
        byteSuffix = "KB";      <br />
<br />
        byteSize = size + "";       <br />
        size = size / Math.Pow(2, 10); <br />
        adjustedSize = size.ToString("N2");<br />
      }<br />
        <br />
      this.statusFileSize.Text = adjustedSize + " " + byteSuffix;<br />
      this.statusFileSize.ToolTipText = adjustedSize + " " + byteSuffix + " (" + byteSize + " bytes)"<br />


this is how i get encoder
<br />
StreamReader reader = null;<br />
<br />
      try<br />
      {<br />
        reader = new StreamReader(this.path, true);<br />
<br />
        this.Content = reader.ReadToEnd();<br />
        this.encoder = reader.CurrentEncoding;               <br />
        this.Encoding = encoder.EncodingName;<br />
<br />
        reader.Close();<br />
        <br />
        // set default encoder<br />
        if(this.encoder == null)<br />
        {<br />
          this.encoder = ASCIIEncoding.Unicode;<br />
          this.Encoding = encoder.EncodingName;<br />
        }<br />
      }<br />
      catch (Exception e)<br />
      {<br />
        Debug.WriteLine("Error: " + e.Message);<br />
      }<br />
      finally<br />
      {<br />
        if(reader != null) reader.Close();<br />
      }    <br />


kind regards,
g00fy
AnswerRe: getting file bytesize Pin
Ashok Dhamija18-Sep-05 18:14
Ashok Dhamija18-Sep-05 18:14 
GeneralRe: getting file bytesize Pin
g00fyman18-Sep-05 18:45
g00fyman18-Sep-05 18:45 
GeneralRe: getting file bytesize Pin
g00fyman18-Sep-05 18:50
g00fyman18-Sep-05 18:50 
GeneralRe: getting file bytesize Pin
Ashok Dhamija18-Sep-05 19:12
Ashok Dhamija18-Sep-05 19:12 
QuestionNeed 3 Pens Reg, Green and Blue Pin
Anonymous18-Sep-05 15:04
Anonymous18-Sep-05 15:04 
AnswerRe: Need 3 Pens Reg, Green and Blue Pin
FusionCoding18-Sep-05 17:08
FusionCoding18-Sep-05 17:08 
AnswerRe: Need 3 Pens Reg, Green and Blue Pin
Christian Graus18-Sep-05 17:50
protectorChristian Graus18-Sep-05 17:50 
QuestionDraw larger drawings Pin
radic.feng18-Sep-05 15:00
radic.feng18-Sep-05 15:00 
AnswerRe: Draw larger drawings Pin
radic.feng18-Sep-05 16:51
radic.feng18-Sep-05 16:51 
QuestionProblems with Setup Project Pin
surfman1918-Sep-05 14:29
surfman1918-Sep-05 14:29 
GeneralRe: Problems with Setup Project Pin
seee sharp18-Sep-05 17:44
seee sharp18-Sep-05 17:44 
GeneralRe: Problems with Setup Project Pin
surfman1919-Sep-05 0:03
surfman1919-Sep-05 0:03 
Questionserial number for my application Pin
Sasuko18-Sep-05 12:18
Sasuko18-Sep-05 12:18 
AnswerRe: serial number for my application Pin
surfman1918-Sep-05 14:26
surfman1918-Sep-05 14:26 
AnswerRe: serial number for my application Pin
Ashok Dhamija18-Sep-05 18:46
Ashok Dhamija18-Sep-05 18:46 
QuestionColumns Pin
Taurian11018-Sep-05 11:56
Taurian11018-Sep-05 11:56 
AnswerRe: Columns Pin
deep718-Sep-05 18:34
deep718-Sep-05 18: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.