|
Hello All Gurus,
I have one client server application where I am sending files from client to server ,like file upload functionality , File could be any file eg .exe , .jpeg .
I am sending data in byte array through network stream /sockets.
File is tranfering correctly but when I am trying to open any .pdf or .jpeg file after transfer it is giving me error.cannot open file not in correct format.
Only txt file working correctly..
Please advise.
Regards ,
nishu
|
|
|
|
|
The file your saving on the server is, obviously, being corrupted. Either your client isn't sending the file byte-for-byte, or the server isn't receiving it properly, or it's not writing it byte-for-byte to disk. Without seeing anyn of your client and server code, it's impossible to tell you what's going wrong.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
It probably means the bytes are corrupted -- either you didn't get all the bytes or you didn't get them all in the right order. Do a file compare between original and transferred version to see if they're the same.
|
|
|
|
|
I'm wondering if the server is writing out a text file or a binary file? If the server is writing out a text file, that would explain this behaviour...
Phil
|
|
|
|
|
Yes it would. He's probably using TextReader/Writer, or some other text-only stream, probably even with an Encoding he specified, for reading/writing binary files. That'll corrupt 'em pretty quick.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks for your reply...
I am not using TextReader/Writer ,I am using Filestream to write in the file....my code is as below,
stream = client.GetStream();
writer = new System.IO.StreamWriter(stream);
freader = new System.IO.FileStream(@"d:\AJAX_process.jpg", System.IO.FileMode.Open);
long length = freader.Length;
writer.WriteLine(length.ToString());
writer.Flush();
byte[] buffer = new byte[length];
freader.Read(buffer, 0,(Int32)length);
freader.Flush();
freader.Close();
//write buffer to network stream//
stream.Write(buffer, 0,(Int32)length);
stream.Flush();
stream.Close();
writer.Close();
One more question....
Do I need tto sent byte after byte....??
Regards ,
nishu
|
|
|
|
|
sorry I forgot to write but The above is sending data ....
stream=client.GetStream();
reader = new System.IO.StreamReader(stream);
filename = reader.ReadLine();
length = long.Parse(reader.ReadLine());
byte [] buffer = new byte[length];
stream.Read(buffer, 0,(int) length);
fwriter = new System.IO.FileStream(@"d:\new.jpg", System.IO.FileMode.CreateNew);
fwriter.Write(buffer, 0,(int) length);
MessageBox.Show("write to file done");
Regards ,
nishu
|
|
|
|
|
I want to enable a user to export a single MS Access Data Table from a multitable database into a separate database. More, I want the user to be able to create the separate database file at the same time he/she exports the datatable to that separate database file. I could simply use File.Copy to copy the entire database to the separate database file, but the users won't need the entire database, just the one table to allow them to archive certain information. Is this possible?
|
|
|
|
|
who can teach me to hacker ID games??
|
|
|
|
|
Noone around here will ever help you steal someone's software. Think about it. You just asked a bunch of developers, who making their living writing and selling software, how to steal the very software they're writing!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
If I told you I'd be cutting my own throat!
|
|
|
|
|
I was wondering if anyone knows how to access a control (like a textbox control) that is attached to a MS Word document that has already been created. I need to do it using C#. Any example would be a big help.
|
|
|
|
|
|
I opened up a new Word Doc. Started recording the macro. Created a Text Box and started typing some text in it. Stopped recording of the macro and did an Edit of the Macro to see the code and this is all i got out of it:
ActiveDocument.ToggleFormsDesign
Selection.InlineShapes.AddOLEControl ClassType:="Forms.TextBox.1"
ActiveDocument.ToggleFormsDesign
ActiveDocument.ToggleFormsDesign
ActiveDocument.ViewPropertyBrowser
ActiveDocument.ViewPropertyBrowser
It still does not tell me how to access the Text Box.
I can create on for the Word doc with
aDoc.InlineShapes.AddOLEControl(ref TextBoxName,ref Range);
put i need to get one that is already in the word doc
any ideas?
|
|
|
|
|
So save that document with the textbox in it. press return a few times. Start a macro click on the textbox, stop the macro. I would guess the macro code would have something that what you have above. So I would guess that you need to know which text box it is. It looks like they are numbered. YOu added one so the id is forms.textbox.1. So if you put the correct number in there you should be able to select the text box.
Ben
|
|
|
|
|
Hi All
I would like to implement the "CANCEL" operation while I'm copying a large file because it can takes too much time. I would like to do it in wondeful C# language.
Do you think that creating a separate Thread for the copy operation (implemented using File.Copy method) that could be killed when I call the CANCEL button put in a different Thread?
Regards
ManuStone
|
|
|
|
|
|
Hello
I have a computer which has a share folder with username and password.
I want to copy a file from this folder without having to map the folder into a drive just by a simple copy. What copy command accepts also username and password for file copying purpose ?
Thanks,
Clint
|
|
|
|
|
I don't know of any, but what I do is make sure what ever user is running the process that needs to copy things from the share also exists on that computer with the correct rights. That way there is no prompt for username or password.
Hope that helps.
Ben
|
|
|
|
|
Hello experts,
What do you do when your catch block contains statements with a potential for throwing their own exceptions?
Thanks in advance,
Shy.
|
|
|
|
|
shyagam wrote: What do you do when your catch block contains statements with a potential for throwing their own exceptions?
Same answer as any other situation where exceptions might be thrown: Decide whether it can be handled at that point and catch it if it can, otherwise let it unwind the stack until it is caught.
NOTE: Some exception handling blocks deliberately throw an exception (and place the original exception as the InnerException to the new exception)
|
|
|
|
|
Colin Angus Mackay wrote: Decide whether it can be handled at that point and catch it if it can
Does it mean I should nest a new try/catch block inside of the original one?
|
|
|
|
|
If you have exceptions that you can handle there yes.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
I'm considering a transition from C++/MFC to C# for an upcoming project. Can anyone tell me where to find articles or examples of how MFC concepts might be mapped onto a C# implementation. For example are there any implementations of the Doc/View pattern, printing and previewing, menu enabling and updating etc? Or have I missed the point - is it back to the ancient and abominable collection of forms?
Thx++
|
|
|
|
|