|
wish you all a happy new year..! thanx for your reply . i had made a mistake the constructor with the serialzationinfo and the streamcontext is the one which will be called at deserialization. so i had to calculate the amount in this . then the constructor will be changed to
protected _object(SerializationInfo info, StreamingContext context)
{
itemCnt = info.GetInt32("itemCnt");
itemName = info.GetString("itemName");
unitPrice = info.GetDecimal("unitPrice");
amount = itemCnt * unitPrice;
}
but the problem is still remaining...the itemCnt,itemName and unitPrice are getting accurately , only the calculation is not taking place..
|
|
|
|
|
Hi,
I tried created a windows service which does a file transfer from the folder its watching whenever a new file being created in it.I am getting an exception saying "The path is not of a legal form." on trying to start the service. An the path the exception refering to is the path that i set to the FileSystemWatch. Path property. I dont understand why it happens. The path is "D:\Test". The folder has all the permission to access.
Can anyone help me out.
|
|
|
|
|
When setting your path did you use an @ ?
string path = @"D:\Test";
Without that, that \T will likely get converted to a tab which would not be a legal form.
Regards,
Rob Philpott.
|
|
|
|
|
Without the code it is difficult to help, can post it please? Remember to use <pre> tags !
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Service1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;
namespace FileTransfer
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
FileTransferWatcher.Created += new System.IO.FileSystemEventHandler(FileTransferWatcher_Created);
}
catch (Exception ex)
{
EventLog.WriteEntry("Message : " + ex.Message);
}
}
void FileTransferWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
System.IO.File.Copy(e.FullPath, @"D:\");
}
protected override void OnStop()
{
}
}
}
Service1.Designer.cs
namespace FileTransfer
{
partial class Service1
{
private System.ComponentModel.IContainer components;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.FileTransferWatcher = new System.IO.FileSystemWatcher();
this.FileTransferWatcher.EnableRaisingEvents = true;
this.FileTransferWatcher.Path = "D:\\Test\\";
this.ServiceName = "FileTransfer";
}
#endregion
private System.IO.FileSystemWatcher FileTransferWatcher;
}
}
The bolder statement is were the exception is thrown.
|
|
|
|
|
You need to set
this.FileTransferWatcher.Path = "D:\\Test\\";
before this
FileTransferWatcher.EnableRaisingEvents = true;
As the inital path of a FileSystemWatcher is an empty string.
Also, as a side note, hardcoding the paths in magic strings isn't a good plan (though obviously the code posted is, by definition, unfinished). I'd also move out the FileWatcher/Transfer code into a separate class that deals with this and let the service just handle the service related stuff.
The other thing is, if you can, I'd run this as a console app and then convert it into a service later as debugging services is trickier.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Thanks Keefb!
I got the mistake i have done... Also as you said i should have started with as a console application.
|
|
|
|
|
This is just a guess, but does the directory exist? I've looked at the property's code through Reflector, and that's the only thing that will throw the exception.
By the way, your File.Copy will fail, because you haven't specified a source filename, just the parent directory.
|
|
|
|
|
Sorry, I try to understand what you are doing:
void FileTransferWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
System.IO.File.Copy(e.FullPath, @"D:\");
}
/pre>
Are you copying a file to your observed directory when you register the handler?
|
|
|
|
|
Hi All,
Hope everyone had a Merry Xmas and Happy New Year.
Just a question...I have made an RSS Feed which is syndicated by the Mozilla and IE , as an output of an XML file. However when either of the feeds show, they show the pubDate as being totally different dates to what is shown in the XML file. Even when I look at the source, the XML file still shows the correct dates as opposed to what is shown in the browser.
What do you guys think is the problem? Heres my code. Cheers.
public static void CreateNewsFeed(string mappath)
{
FileStream fs = null;
StreamWriter sw = null;
try
{
using (SqlConnection conn = Connection.connect())
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "ShowNewsFeed";
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = cmd.ExecuteReader();
fs = new FileStream(mappath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
sw = new StreamWriter(fs);
sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//ISO-8859-1
//xmlns:atom=\"http://www.w3.org/2005/Atom\"
sw.WriteLine("<rss version=\"2.0\">");
sw.WriteLine("<channel>");
sw.WriteLine("<title>Company Name</title>");
sw.WriteLine("<link>http://www.companyname.com.au/Home/News/News.aspx</link>");
sw.WriteLine("<description>News and the latest updates</description>");
sw.WriteLine("<language>en-us</language>");
while (reader.Read())
{
DateTime dt = (DateTime)reader["datePosted"];
sw.WriteLine("<item>");
sw.WriteLine("<title>" + reader["title"].ToString() + "</title>");
sw.WriteLine("<link>http://www.companyname.com.au/NewsArticle.aspx?newsID=" + reader["newsID"] + "</link>");
sw.WriteLine("<description>" + reader["description"].ToString() + "</description>");
sw.WriteLine("<pubDate>" + dt.ToString("R") + "</pubDate>");
sw.WriteLine("</item>");
}
sw.WriteLine("</channel>");
sw.WriteLine("</rss>");
sw.Close();
fs.Close();
}
}
catch (Exception m)
{
throw new Exception(m.Message);
}
}
|
|
|
|
|
donno really, might be that the browser is rewriting the timestamps.
I tried your rss online at:
http://www.w3schools.com/rss/tryrss.asp?filename=rss_ex_pubdate[^]
and it works fine:
Company Name
News and the latest updates
RSS Version: 2.0
Feed Updated: Thu, 17 Aug 2000 23:32:32 GMT
Some Title: Some description
Published: Thu, 27 Apr 2006
modified on Thursday, December 31, 2009 10:00 AM
|
|
|
|
|
I am working on developing a browser helper object for IE. I have to automatically login in to some sites.
These are issues I am facing:
1. In one of the sites, although I use a Navigate2() function of IWebBrowser2 with 'Basic' Authorization header, the site neglects it because it looks like a javascript function is run while loaded and it opens up a pop asking for credentials again (response header with WWW-Authenticate and Basic realm).
2. There are a few other sites where I succeed in logging in by sending Authorization header. But if I click on any of the links or try to browse, they again ask for credentials - some times with same domain or a different domain when it happens to open a new window.
I need a way to store login credentials as a part of internet explorer which the browser can add to every request for a domain or a set of domains. Or, if there are any other solutions, please do suggest.
Please do let me know if I am not clear.
Thanks,
Vijay
|
|
|
|
|
I think Cookies will be the best solution for this
|
|
|
|
|
Sipder, thanks for the suggestion.
Could you elaborate more on that, pls? Won't the server look for an authorization header? How does one make sure cookies are read when credentials are required?
Thanks,
Vijay
|
|
|
|
|
How do i use the edit distance and longest common subsequence algortihms for building a spelling checker application ??
|
|
|
|
|
You could start by reading this[^] article.
/ravi
|
|
|
|
|
|
Hi All,
I have one sample sql query and in where condition i need to put one value which is coming from dictonary object.
sample sql query: select * from XYZ where column1= {0}
so, i used string.Format(sql,searchvalue),
sql: query with where condition
searchvalue: Dictonaryobject(holds key and value)
but while debugging it is not replacing dictionary value and it is replacing text like
'System.Collections.Generic.Dictionary`2[System.String,System.String]'
i am a bit confused why it is not replacing with dictionary value.
can anybody help on this?
fttyhtrhyfytrytrysetyetytesystryrty
|
|
|
|
|
yadlaprasad wrote: so, i used string.Format(sql,searchvalue),
You need to use searchvalue["..."] where ... will be your key value. If you directly use searchvalue you will only get System.Collections.Generic.Dictionary`2.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
To add to Abinhavs' answer: Don't do it that way anyway! When you do, you leave your database open to an SQL injection attack[^]
Do it this way
SqlCommand cmd = new SqlCommand("SELECT * FROM xyz WHERE column1=@SV");
cmd.Parameters.AddWithValue("@SV", searchvalue); Note that the convention is SQL keywords in uppercase, tablenames and fields lowercase.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Dear all,
I am new to C# programming and I need some guide on this problem. I am using MicroSoft Visual Studios 2005 C#.
I am given a task where i have to use the detections(in byte) received by the serial port, to
store them into points and appear on the interface form.
I need to:
1) use ReadByte Method to receive a single byte at a time from the serial port and to give a unique initial to the received byte detections by the HS0038B receiver. The detections must be categorised as X1 and Y1.
2)Create an ArrayList to store the bytes when the function ReadByte receive single byte.
Can anyone provide me with a small workable codes?
Thank you very much
|
|
|
|
|
I want to move a file with the following function but i get UnathorizedAccessException thrown. What could be the problem. When i try to move it to My Documents, it works just fine, only when i move it to the C Drive it throws the Exception mentioned. I'm really stuck.
private void MoveFile()
{
string fileName = "myFile.txt";
FileInfo fInfo = new FileInfo(fileName);
fInfo.MoveTo(@"C:\"+fileName);
MessageBox.Show("Done");
}
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Have you got Admin rights on the box? Sounds pretty much to me like you don't have access to c:\
Can you manually move a file there in explorer?
Regards,
Rob Philpott.
|
|
|
|
|
When i move a file in C, i get a pop up saying Destination Folder Access Denied, then asks me to provide administrators permission. I click on Continue to get permission. Then i get permission and the file is moved. Is there a way my program can make such permission requests? What is the best way to go about this?
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Well, security isn't really my thing, but your problem is clear enough.
First off, can you move the file somewhere other than root?
If not, you can fiddle around with the folder security on it and make sure the account you're using has full access to it.
And, if its that stupid UAC vista thing, I'd consider turning it off completely if you can. It's most annoying.
Regards,
Rob Philpott.
|
|
|
|