|
grmihel2 wrote: had no clue where to start
The best thing I can suggest is to look at the classes and methods you are using to read the file, and find the opposite methods for writing. Are you sure that you are reading the file in binary and not using any form of character conversion and thus corrupting the file? Are you verifying every method call is successful and that the captured length of the file matches the original?
Also, what does this line do, I've not seen this call?
byte[] file = WriteFile(filSti, fil);
I must get a clever new signature for 2011.
|
|
|
|
|
Oh yes, sorry, the WriteFile function is following:
public byte[] WriteFile(string filePath, StoredFile file)
{
byte[] buffer = file.FilContent.ToArray();
FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
int length = (int)fileStream.Length;
buffer = new byte[length];
int count;
int sum = 0;
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count;
}
finally
{
fileStream.Close();
}
return buffer;
}
|
|
|
|
|
Why are you reading a file in your WriteFile() method? You should be getting the file content from your database and writing it to a disk file. The above code seems somewhat confusing.
I must get a clever new signature for 2011.
|
|
|
|
|
True, I can see that the Write method didn't make sense
I'm not really used to do these RW files programming, so I'm sorry for newbieness, but you have to learn it some how
Anyways, I have attempted to rewrite another write method like this:
public void WriteFile(string filePath, StoredFile file)
{
byte[] data = file.FilContent.ToArray();
FileStream fileStream = new FileStream(@"d:\temp\doctest.docx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
int length = (int)data.Length;
int buffer = 1000;
fileStream.SetLength(length);
fileStream.Seek(length - buffer, SeekOrigin.Begin);
fileStream.Write(data, 0, buffer);
fileStream.Flush();
}
finally
{
fileStream.Close();
}
}
The doctest.docx file is now 14KB as the original, so something seems right. But the file is still somehow corrupted, cuz I can't open the docx without an error message telling me the data in the Word document is wrong... Notice that the file.Filcontent is the varbinary value from the Database.
By the way, is it really so simple, that when I'm sure that its a .docx file I store in my DB as varbinary, I can just store it on local machine as a file with the same extension? No need of creating a Word application object and write it through that?
|
|
|
|
|
You seem to be getting confused with your file IO code:
int length = (int)data.Length;
int buffer = 1000;
fileStream.SetLength(length);
fileStream.Seek(length - buffer, SeekOrigin.Begin);
fileStream.Write(data, 0, data.Length);
fileStream.Flush();
I would suggest spending some time here[^] to get a better understanding of the FileStream class.
I must get a clever new signature for 2011.
|
|
|
|
|
Thanks a lot! That worked like a charm... I certainly need to study some more of the FileStreamers posibilities, thats a whole new world opening, but ain't that the beauty of coding, to explorer new posibilities?
Yet again, thnx for your expertise, it works brilliant now.
|
|
|
|
|
Happy to help, good luck!
I must get a clever new signature for 2011.
|
|
|
|
|
Hi,
I developed a desktop application using SQL Compact, used Entity Framework. Now I see, Entity Framework's connection string is not that simple, it stored many information in the connection string in app.config file. So, I do not touch that file. But what I see, the database folder is user |DataDirectory| which is actually Application.StartUpPath. When I distribute my program to end users, will they be able to run my application where the database is in the program files folder ? I know it was not a problem for XP. But when Vista came, the 'User Account Control' feature prevented accessing any files in Program Files folder. What about now ? Is that problem gone in Windows 7 ? IF NOT, then, how can I make the connection string dynamic (setting programmatically) for Entity framework ? Although I extremely like to use Application.StartUpPath to be my data store as it is easy for maintainability.
|
|
|
|
|
Your setup routine could add write privileges to the users, either to the startup directory or to the file(s) of your database.
|
|
|
|
|
The data should not be in the program directory.
|
|
|
|
|
HI all,
I am having a value in a encrypted format and the encryption and decryption technique used id 3DES.And also i am having a decryption key which is like "abcdefghiABCDEFGHI12345jKlMnopqrstuvWxYz67890ZLM" (i.e., length is 48).
Now can any one tell me how can i decrypt the encrypted value using decryption key.
And i am using the DNN database.
Thanks in advance.
modified on Thursday, February 17, 2011 11:41 PM
|
|
|
|
|
Decryption is the reversal of encryption: Whatever code you used to encrypt should provide the basis for your decryption routine.
There is an example of doing both here[^] which may help you, although it does some ancillary stuff you may not want. However, it should compare to your encryption code reasonably easily.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
According to Wikipedia (http://en.wikipedia.org/wiki/Triple_DES[^]), Triple DES uses three keys of 56 bits(! that is 7 bytes each, or 21 bytes in total). Something seems to be wrong with your 46 characters string. Perhaps a hash function is required to get the "real" key from your string?
|
|
|
|
|
Take a look at there[^] having same type question with some perfect solution.
hope it will works for you.
|
|
|
|
|
What is the mechanism to prevent other users to use class libraries developed and used in distributed UI application, neither as stand alone or by adding the reference to the UI application?
In native dll it is possible to handle licening e.g. in dll load event.
Чесноков
|
|
|
|
|
Use Friend Assemblies: Friend Assemblies at MSDN[^]
Your functions and classes can only be used by assemblies using a certain namespace, further protection is done using keys. This does not prevent ILDASM from disassembling though.
To prevent ILDASM from disassembling it, add this: [assembly: SuppressIldasmAttribute()][^]
|
|
|
|
|
I experienced that from the other side: a long time ago, I tried to use a data mining dll from SQL Server in my application. When I instantiated the COM object, I got a message that I had no license to do so.
From that experience, I'd think of some licensing mechanism, likely with asymmetric encryption (only the "public" key would be stored somewhere in the application and could be read by reverse engineering).
The reference to your dlls could still be added, but they would not be useful.
|
|
|
|
|
You might want to look at the ILMerge tool.
|
|
|
|
|
Hi all,
I am currently trying to send a COM Event from a .NET Assembly to another application. Therefore I am applying the approach that's found multiple times across the internet. Here it's outlined for short.
[ComVisible(false)]
public delegate void OnNotifyDelegate();
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface Events
{
void OnNotify();
}
[Guid(EventSource.ClsID)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(Events))]
public class EventSource : ServicedComponent, EventInterface
{
private const string ClsID = "4A235195-E8B3-473b-8F14-F7F0ADFC40E0";
public event OnNotifyDelegate OnNotify;
public EventSource() { }
public void CauseOnNotify()
{
OnNotify();
}
}
Now, to raise the OnNotify Event I created a small WPF Application with a button, whose Click handler invokes the method CauseOnNotify above. I don't show it here, because that would be verbose.
What I get is a NullPointerException because OnNotify is at the time it's invoked null.
My question is: None of the examples mentions a instanciation of the delegate (which is why its null, but under which circumstances does this exception not happen? Where is the instance coming from?
thanks in advance
Lars
#pragma error( disable : * )
|
|
|
|
|
When some other object has registered for the event?
I haven't tested with COM, but it looks similar to raising a "normal" .NET event:
if (this.MyEvent != null)
{
this.MyEvent(this, new EventArgs());
}
Only after an object has registered for MyEvent, it is different from null.
|
|
|
|
|
Hello
In my program I dynamically load DLL, but I have some problem. Dll use my program config and not his own confg. Here is part of the code:
Assembly assemblyInstance = Assembly.LoadFrom(assembly);
Object ProviderClass = assemblyInstance.CreateInstance(type);
object[] methodMaramList = new object[1];
methodMaramList[0] = logInInfo;
if (providerInfo.GetInformation == false)
throw new Exception("This provider does not support get abonent function.");
authorizationResponse = (AuthorizationResponse)assemblyInstance.GetType(type).InvokeMember(method,
BindingFlags.Public |
BindingFlags.InvokeMethod |
BindingFlags.Instance,
null,
ProviderClass,
methodMaramList);
|
|
|
|
|
Which one of the code lines causes a problem? What's the error message?
What is "providerInfo"?
|
|
|
|
|
Hi,
When I try to enter ALT+1(Num Lock pad) in a text box, its loading as ☺ in textbox. How to avoid such symbols. I tried to avoid taking input from num lock pad and wrote the below code. But still its showing symbols. Please let me know how to avoid those. Thanks in advance
private void txtHotKey_KeyDown(object sender, KeyEventArgs e)
{
//for Num Lock keys 0-9
if (e.KeyValue==18 || e.KeyValue > 95 && e.KeyValue < 106)
{
return;
}
}
|
|
|
|
|
Pressing Alt with the number keys generates special characters with the value of the keys pressed. So for example Alt+65 would give the character A which has the decimal value 65 (hex 41).
I must get a clever new signature for 2011.
|
|
|
|
|
thats fine.. But how to avoid those special symbols programmatically.
|
|
|
|