|
You are correct. I did ask the question improperly. I do have one final question:
In a file transfer OUT: Does LSB of the FIRST byte transfer out before MSB? Followed by the LSB of the SECOND byte, then the MSB? Followed by the LSB of the LAST byte , then the MSB?
In a file transfer work the same way when I file comes IN?
|
|
|
|
|
The bytes in a file are exactly what they are, the bits of those bytes are not mixed in weird ways.
|
|
|
|
|
//I AM TRYING TO REVERSE THE PROCESS OF BYTE TO DECIMAL CONVERSION WHICH WAS SUCCESSFUL. I THOUGHT THAT REVERSING THE CODE WOULD REVERSE THE PROCESS AND DECIMAL TO BYTE CONVERSION, BUT IT IS NOT WORKING.
<pre>using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
long Totbyte = 0;
string filePath = null;
DirectoryInfo da = new DirectoryInfo("C:\\Folder");
FileInfo[] Arr = da.GetFiles();
foreach (FileInfo ap in Arr)
{
Totbyte = ap.Length;
filePath = ap.FullName;
}
Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
string temPath = Path.GetTempFileName();
byte[] data = new byte[Totbyte];
if (File.Exists(temPath))
{
data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
}
decimal[] arry = new decimal[Totbyte];
for (int count = 0; count < data.Length; count++)
{
arry[count] = data[count];
}
byte[] data2 = new byte[Totbyte];
for (int count = 0; count < arry.Length; count++)
{
data2[count] = arry[count];
}
FileStream file = new FileStream(filePath, FileMode.Create);
BinaryWriter binarystream = new BinaryWriter(file);
binarystream.Write(data2);
binarystream.Close();
}
}
}
|
|
|
|
|
Follow the error message. It tells you what to do. But I'm a nice guy (well, sometimes), so here you go:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
long Totbyte = 0;
string filePath = null;
DirectoryInfo da = new DirectoryInfo("C:\\Folder");
FileInfo[] Arr = da.GetFiles();
foreach (FileInfo ap in Arr)
{
Totbyte = ap.Length;
filePath = ap.FullName;
}
Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
string temPath = Path.GetTempFileName();
byte[] data = new byte[Totbyte];
if (File.Exists(temPath))
{
data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
}
decimal[] arry = new decimal[Totbyte];
for (int count = 0; count < data.Length; count++)
{
arry[count] = data[count];
}
byte[] data2 = new byte[Totbyte];
for (int count = 0; count < arry.Length; count++)
{
data2[count] = (byte)arry[count];
}
FileStream file = new FileStream(filePath, FileMode.Create);
BinaryWriter binarystream = new BinaryWriter(file);
binarystream.Write(data2);
binarystream.Close();
}
}
}
By the way, may I ask what this is for? Converting all the bytes of a file to decimals is a pretty weird thing to do. I have a gut feeling there might be a nicer solution.
|
|
|
|
|
I did figure out the casting (byte) from one of my books.
Also filePath (FileStream file = new FileStream(filePath, FileMode.Create)) did not work. I had to replace filePath with an actual path. When I open the file, it was looked like garbage. It was not the same file that I started with. It got corrupted at some point.
What is it for: Well it is a very long story and really don't mind sharing my thoughts after I prove my theory. I would be more than happy to explore a nicer, shorter, more stream line and robust solution. Please assist.
|
|
|
|
|
You might be interested in File.WriteAllBytes(path, bytes) to making writing them back a little simpler.
computerpublic wrote: When I open the file, it was looked like garbage. It was not the same file that I started with. It got corrupted at some point. Is that with the code I posted? Or else, with what code?
|
|
|
|
|
My first idea was to use WriteAllBytes, but books did not talk about it. And the online resources did not show me properly how to code it. I found the other solution which i used, but I am getting garbage. Can you please show me how to make it work?
|
|
|
|
|
It should work without special effort. Did you verify that the bytes you give it are OK?
|
|
|
|
|
computerpublic wrote: You keep saying you don't know what I am trying to do. I think it is pretty obvious that ...
Of course it's obvious to you - you're the one who's having the problems. The trick is to clearly explain the problem to someone else, remembering that we can't see your screen, access your hard-drive, or read your mind.
None of the questions you've posted in the last couple of days have had a clear explanation of what you're trying to do. They've mostly been code-dumps with a few cryptic comments along the lines of "this line doesn't work". The code you've posted doesn't seem to make any logical sense, because you haven't explained what you're trying to do.
The code you posted in this question is almost identical to the code you posted in the question below[^]. It seems you either didn't read Pete's answer, or you didn't understand it, because now you're just calling a random method and trying to assign the result to an incompatible type. Reposting a virtually identical question whilst ignoring the previous answers is not a good way to get people to help you!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
<pre>
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
long Totbyte = 0;
string filePath = null;
DirectoryInfo da = new DirectoryInfo("C:\\Folder");
FileInfo[] Arr = da.GetFiles();
foreach (FileInfo ap in Arr)
{
Totbyte = ap.Length;
filePath = ap.FullName;
}
string temPath = Path.GetTempFileName();
byte[] data = new byte[Totbyte];
if (File.Exists(temPath))
{
data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
}
int[] arry = new int[Totbyte]; for (int count = 0; count < data.Length; count++)
{
arry[count] = Convert.ToDecimal(BitConverter.ToInt(data,count));
}
}
}
}
|
|
|
|
|
You have created arry as a byte array of integers and you are trying to stuff a decimal value into it. There's no need to do Convert.ToDecimal on the output of BitConverter (and it should be ToInt32 - not ToInt).
|
|
|
|
|
I was expected a byte value to be no larger than 255, but I am now getting values 10 digits long. Please kindly explain what is going on.
|
|
|
|
|
The issue you are hitting is because you are misusing BitConverter[^]. If you just want to convert a byte to an int, then you can simply assign the values across if you want to because a byte will upcast into an int quite happily. There's no need to do a conversion in this case.
|
|
|
|
|
Hi All,
We Develop a financial system which is a desktop c# application and we need to add a functionality that allow to pay by the visa cards, my question is what I should have to develop this functionality and what is the best 3rd party to use, and is the 3rd party should have an API's to use it in my Application.
Please help me ASAP because I'm a new in this.
Thanks for your efforts.
|
|
|
|
|
never done this, but my initial idea would be to get a hold on the party responsible of payment.
Usually payments go through a TRUSTED third party provider. In Belgium we have "Ogone" for example. Your application forwards payment details to this company who will ask the user for credit card details. Then the provider, when payment is approved redirects the user back to you and will notify you if payment was done or not.
So first thing to do is get in contact with such a provider.
Hope this helps.
|
|
|
|
|
V is absolutely right - go with a reliable card transaction service company.
And this is really, really important:
Never, ever, accept code from a insecure website to handle anything to do with real money.
You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties.
Only get such code from reputable card transaction service companies - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be!
Which means: Don't ask here - always go back to them for assistance. Don't worry about looking stupid or lacking in knowledge: it's a lot, lot better than looking at a prison cell...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Too bad we can only click the UpVote button once.
|
|
|
|
|
You can create multiple account to UpVote...
Thanks
-Amit Gajjar
|
|
|
|
|
Yeah, I'm not into having socket puppets.
|
|
|
|
|
OriginalGriff wrote: V is absolutely right
I should print this in large curly letters and frame it
|
|
|
|
|
I recommend that you do not use paypal.
I was scammed by someone buying a key to my software then telling paypal the transaction was a fraud - they got to keep the key and were refunded.
So due to this terrible service from paypal I now broadcast this negative experience far and wide
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hey Guys,
I need your assistance, am struck up with an issue.
Issue: I have retrived a SQL data into a DataGridView, It has the below column header names like (Package_ID, Package_Name etc.)
I used the below code to copy the data in DataGridview to Excel.
Copying is fine, but am not getting the colum headers which are visible in my DatagridView. (Package_ID, Package_Name etc.)
Other than the Column headers all other data are getting copied.
the code i used:
private void copyAlltoClipboard()
{
dataGridView1.SelectAll();
DataObject dataObj = dataGridView1.GetClipboardContent();
if (dataObj != null)
Clipboard.SetDataObject(dataObj);
}
private void btn_Export_Click(object sender, EventArgs e)
{
copyAlltoClipboard();
Microsoft.Office.Interop.Excel.Application xlexcel;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlexcel = new Excel.Application();
xlexcel.Visible = true;
xlWorkBook = xlexcel.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Excel.Range CR = (Excel.Range)xlWorkSheet.Cells[1, 1];
CR.Select();
xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
}
i want my column headers also need to be copied to Excel.
Please assist.
|
|
|
|
|
Mohan Subramani wrote: i want my column headers also need to be copied to Excel. The headers aren't "data"; if you copy the data to Excel, then that's what get's copied. You could loop through the columns before exporting and write those to the first row.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
hello,i wanna create a software with c# that i will use datagridview,and will use LINQ,how can i fetch data from database in to datagridview that when scroll into down data one by one fetch from database? please help me!!!
|
|
|
|