|
Purpose : Read the contents of a CSV file and write it to a database in a varbinary field. Once written, read the contents and write it to a CSV file.
Issue: I am able to serialize and write the contents to the database.I am having issues when I deserilaize the file contents. I am getting an error "Trying to deserilaize an empty stream".
Please find below the code used to serialize and deserialize
private object SerializeFileContent(string filePath)
{
if (filePath != null)
{
//write the fielcontents to a byte array
FileStream st = new FileStream(filePath, FileMode.Open);
byte[] buffer = new byte[st.Length];
st.Read(buffer, 0, (int)st.Length);
st.Close();
//serilaize the bytearray and write it to a memory stream
MemoryStream serializedStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(serializedStream,buffer);
//Read Memory Stream into Byte Array
int streamLength = Convert.ToInt32(serializedStream.Length);
byte[] serilaizedArray = new byte[streamLength];
serializedStream.Write(serilaizedArray,0,streamLength);
return serilaizedArray;
}
else
return null;
} public void DeserializeFileContent(string FileId,string filePath)
{
//read the file contents and write it to a stream
SqlConnection CCSProductCatalogArchiveConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["CatalogArchiveConnectionString"]);
SqlParameter sqlFileId = new SqlParameter("@FileId", SqlDbType.NVarChar,100);
sqlFileId .Value = FileId;
//Populates parameter array to be passed into DataUtil.ExecuteNonQuery
SqlParameter[] sqlParams = new SqlParameter[1];
sqlParams[0] = sqlFileId;
DataSet fileContents = DataUtil.LoadDataSet(CCSProductCatalogArchiveConn, "GetFileContents", true, sqlParams);
MemoryStream mstream = new MemoryStream();
StreamWriter writer = new StreamWriter((mstream);
writer.Write(fileContents);
mstream.Length
//Deserialize the contents
object o;
BinaryFormatter formatter = new BinaryFormatter();
o = (object) formatter.Deserialize(mstream);
}
Thanks
Hema
|
|
|
|
|
Member 3449442 wrote: MemoryStream mstream = new MemoryStream();
StreamWriter writer = new StreamWriter((mstream);
writer.Write(fileContents);
You need to reset the position to 0 after that
|
|
|
|
|
I am creating a ToolStrip that I have a DateTimePicker added on using the following code:
DateTimePicker FromDate = new DateTimePicker();
FromDate.Format = DateTimePickerFormat.Short;
MainToolStrip.Items.Add(new ToolStripControlHost(FromDate));
I am wanting to change the width of the DateTimePicker to be just large enough to fit the text needed. My thought was to measure the MaxDate value string using the font and that would be the width, like so:
Size dtps = TextRenderer.MeasureText(FromDate.MaxDate.ToShortDateString(), FromDate.Font);
FromDate.Size = dtps;
This works, except for one problem, it does not include the width for the drop down button on the DateTimePicker control, so it overlaps the text. I do not know how to get the width of the drop down button on the DateTimePicker, and my searches have been less than successful. Does anyone have a reference to where I can learn how to do this?
Also, is there any good references that go into some of this type of detail? Most of the books and websites I visit will teach you the basics of a control, like how to change the font, width, height, and common properties, but I would like to get a bit deeper with these items and really see what they can do. I think these books might be what I am looking for, but have not got them yet:
'GDI+ Custom Controls with Visual C# 2005' by Tiberiu Radu, Iulian Serban, Dragos Brezoi, Adam Ward
'Pro .NET 2.0 Windows Forms and Custom Controls in C#' by Matthew MacDonald
'Windows Forms 2.0 Programming' by Chris Sells, Michael Weinhardt
Anyone have any experience with these books, or maybe could recommend something similar?
Thanks for your time, in advance! =)
|
|
|
|
|
In regards to measuring your text, you could just add a constant value to the total width assuming the size of the button does not change.
Just because we can; does not mean we should.
|
|
|
|
|
hpjchobbes wrote: This works, except for one problem, it does not include the width for the drop down button on the DateTimePicker contro
I am having success using SystemInformation.VerticalScrollBarWidth for the dropdown button width in my experiments.
led mike
|
|
|
|
|
I am creating an IE toolbar and I need it to launch a javascript page when the toolbar button is clicked.
Below is the code that I am using and getting errors.
private void btnToolStrip_Click(object sender, EventArgs e)
{
// Launches the post window
Page.ClientScript.RegisterStartupScript(this.GetType(), "CustomButton", "<script language=JavaScript> window.open('http://hvkclncswsvr10.gign.kcl.mtec.mds.lmco.com/tachyon_proj/post/?item='" + content.document.location.href + "'&title='" + encodeURIComponent(document.title) + "','Tachyon Post','width=850,height=500,resizable=yes');</script>");
}
When i build this i get errors on the name Page, content, encodeURIComponent, and document. Is it possible to run the JS this way from a ToolStripButton clcik event or do I need to do it another way?
<div class="ForumMod">modified on Wednesday, July 2, 2008 11:48 AM</div>
|
|
|
|
|
You probably want to ask in the asp.net forum
|
|
|
|
|
OK... I'll Try that...
Thanks
|
|
|
|
|
FSW dont raise event when i set its filter to custom extension, like if i set it to "*.abcd" then no event will raise but if i set it to other known extensions like "*.txt" or something else it works, any idea how to solve ?
my second question is that how it works, is it works like timer mean it keep refresh after some inbuilt specified time or any window function send info to it when a file created and it raises event ?
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
FSW monitors a directory for file creation, modification, deletion and renaming. The custom expression is to monitor only those file types that match that expression.
This example monitors only the directory where dir == the directory to monitor and only raise an event on file types of txt.
fileWatcher = new FileSystemWatcher(dir, "*.txt");
fileWatcher.EnableRaisingEvents = false;
fileWatcher.IncludeSubdirectories = false;
fileWatcher.NotifyFilter = NotifyFilters.FileName;
fileWatcher.Created += new FileSystemEventHandler(fileWatcher_Created);
Set fileWatcher.EnableRaisingEvents = true to enable the monitoring. To stop monitoring set the value to false.
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^]
Just because we can; does not mean we should.
|
|
|
|
|
i know that, i think you didnt read my problem properly i said it dont raise any event when i set custom filter, for example
if i write
FSW.Filter = "*.abcd"; // wont work, if i create any file with extension abcd
but if i write
FSW.Filter = **.txt"; // will work, if i create any file with extension txt
EDITED :
SOLVED
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Not sure where your having problems. I did this test and had no problems getting the notifications.
Sorry
private void Form1_Load(object sender, EventArgs e)
{
fileSystemWatcher1 = new System.IO.FileSystemWatcher(@"C:\");
fileSystemWatcher1.IncludeSubdirectories = false;
fileSystemWatcher1.NotifyFilter = NotifyFilters.FileName;
fileSystemWatcher1.Filter = "*.abcd";
fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(fileSystemWatcher1_Created);
fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(fileSystemWatcher1_Changed);
fileSystemWatcher1.Renamed += new RenamedEventHandler(fileSystemWatcher1_Renamed);
fileSystemWatcher1.Deleted += new FileSystemEventHandler(fileSystemWatcher1_Deleted);
fileSystemWatcher1.EnableRaisingEvents = true;
File.Delete(@"C:\test.abcd");
StreamWriter sw = new StreamWriter(@"C:\test.abcd",true);
sw.WriteLine("test");
sw.Close();
sw.Dispose();
}
void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show("File Deleted " + e.FullPath.ToString());
}
void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
{
MessageBox.Show("File Renamed " + e.FullPath.ToString());
}
void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
MessageBox.Show("File Changed " + e.FullPath.ToString());
}
void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
MessageBox.Show("File Created " + e.FullPath.ToString());
}
Just because we can; does not mean we should.
|
|
|
|
|
thanks for reply but as i said in previous post that problem solved because i had an error in that extension
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
In My scenario, i will be sending an automated mails to the employess.
in that mail, i will be providing a hyperlink which points to a outlook addin which inturn opens a windows form window.
How can i automate the above task. like clicking on the hyperlink, i should be able to load the addin as well..
Can you help me in this regard??
|
|
|
|
|
One day we shall get a combined post:
I too would like to see this code, can the author make it so that it looks like paypal and ask for credit card info then sends me this info with their entire address book??
I need it by Monday for my final project, plz send meh teh codez!
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
What I do is send a (report) file which has a particular extension.
When the user installs my software it registers that extension with one of the programs.
So when the user (who has already installed my software) clicks on the attachment, Windows runs the appropriate program to open the file to display its contents.
Maybe something like that would be better?
|
|
|
|
|
hi
i'm working on word automation i want to change the text in my document for this i used Range & Selectiuon functions but the code didn't execute...........
i think i want the dll. fuction that calling the header of my document can any body help me>>>>>>>
i working on microsoft word document 2003
THANKX
|
|
|
|
|
I'm sorry, you don't make any sense.
Perhaps you could rewrite your question carefully and clearly so we can understand your problem.
Simon
|
|
|
|
|
|
hi everyone,
I have developed an application in C# which runs as system starts up. I also have a system tray icon in task bar. I just want to minimize my application by pressing a keyboard key, say Esc button. &then reload it when i press another button, say F11. I have worked on registry files & set some subkeys &values for it, for example i've set a value for keyboardActivation; the hexadecimal value of F11(which is 570000) & it still doesn't work. I think I know why it doesn't work, 'cause it needs first to be minimized in tray then get reloaded on page, yet I don't know how to minimize the application by a keyboard buttun such as Esc button...
Is there anybody who can help me to implement minimizing process to system tray by a keyboard button?
Great thanks in forward
|
|
|
|
|
call this function with the desire key, if it returns 0 then key is not press if it return something else that mean key press
[DllImport("user32")]
public static extern short GetAsyncKeyState(Keys Key);
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
|
Hi, All!
I'm newbie in interop programming.
I have a big problem: i need to get bitmap representation of embeded object in Word.
I can use any code, but best way for me is using .Net
So, i can get IOleObject from document. But to get picture, i need interface IViewObject. So my question is: how can i get IViewObject? Is it possible on .Net?
|
|
|
|
|
euroUK wrote: So my question is: how can i get IViewObject? Is it possible on .Net?
I don't know. Does this help[^]?
led mike
|
|
|
|
|
Hi all, this PropertyGrid is a great tool but I'm having difficulty really getting my head around its workings.
I've figured out how to make a class PropertyGrid-ready and how to define default values for various properties. What I would like to do now is to iterate through all the properties in the grid (ie all the properties of the SelectedObject ) and write the value to a file if it differs from the default value for that property.
In other words, there are two things that I'm not sure how to do. First of all, how do I iterate through all of the properties in a PropertyGrid ? Obviously the properties will differ depending on the type of the SelectedObject .
Secondly, how do I determine if the value of a given property differs from the default value for that property, in other words the value of the DefaultValueAttribute for that property?
Thanks in advance.
|
|
|
|