|
Hi, I'm working on a part of a program where I have a list of file paths and I want to write a method to send each file to the printer. Files in the list would be stuff like .txt and .doc.
I've collected each path in a List<string> docPaths = new List<string>();
and I need to do something like:
foreach (string file in docPaths)
{
}
What would people suggest is the best way to go about this?
Thanks for any help
|
|
|
|
|
Something like this (untried!):
System.Diagnostics.Process printItem = new System.Diagnostics.Process();
printItem.StartInfo.FileName = file;
printItem.StartInfo.UseShellExecute = true;
printItem.StartInfo.Verb = "print";
printItem.Start();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
I'm creating a class derived from System.Windows.Forms.TextBox. I need the Text property to have a default value of "0" and to force a repaint of another property so I've added this:
[DefaultValue("0"),
Category("Appearance"),
RefreshProperties(RefreshProperties.Repaint)]
public new string Text
{
get { return base.Text; }
set { base.Text = value; }
} and added Text = "0"; in the constructor.
The problem is the default value is always "" . If I set Browsable(false) then it acts as I expected. I'd like to be able to have the Text property in the property grid though.
Any ideas?
[edit] Full example code below. [/edit]
using System.ComponentModel;
using System.Windows.Forms;
public class TestTextBox : TextBox
{
public TestTextBox()
{
Text = "0";
}
[DefaultValue("0"),
Browsable(false)]
public new string Text
{
get { return base.Text; }
set { base.Text = value; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: public new string Text
Why are you using 'new' when you should be using 'override' ?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
No particular reason except I had forgotten that Control.Text was virtual
It doesn't help any though, even with override I get the same result.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I've figured a workaround.
1. Override OnTextChanged and implement ISupportInitialize
2. Setting / unsetting a bool flag field in BeginInit and EndInit, then testing for that and string.IsNullOrEmpty(Text) in OnTextChanged, and setting the text to "0" if both are true.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Monday, January 26, 2009 5:35 PM
|
|
|
|
|
hi.
im trying to download html text from 'amazon.com' using this method:
<br />
HttpWebRequest hRequest = (HttpWebRequest)WebRequest.Create(url);<br />
hRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*";<br />
hRequest.ContentType = "application/x-www-form-urlencoded";<br />
hRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.2)";<br />
hRequest.Headers.Add("Accept-Encoding", "gzip, deflate"); <br />
hRequest.Headers.Add("UA-CPU", "x86");<br />
hRequest.Method = "GET";<br />
<br />
HttpWebResponse hResponse = (HttpWebResponse)hRequest.GetResponse();<br />
StreamReader s =new StreamReader(hResponse.GetResponseStream(),Encoding.GetEncoding(hResponse.CharacterSet));<br />
<br />
<br />
string page = s.ReadToEnd();<br />
<br />
i know that amazon uses character set of "iso-8859-1", thats also returned by the httpwebresponse.characterset property.
but for some reason when i examine the string it contains scrambled charecters, so when i want to search that text using all sort of string methods it dosent work.
however if i use the "webclinet" object downloadstring method to retrieve the page it shows up fine, but it also takes him 30 sec to get the string!
i dont know if its like that because of a heavy processing or something else, but its not flexible enough and dosent answer my needs.
anyone have an idea why im getting an invalid string?
|
|
|
|
|
Did you try 'HtmlDecode' the read text?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
from my undersatanding the htmldecode method just replaces encoded characters such as "<" and so on to an html characters.
thats not the issue in my case.
but thanks anyway
|
|
|
|
|
Probably figured this out already but:
// read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0);
Cheers, RG
|
|
|
|
|
[DllImport("Psapi.dll", SetLastError = true)]
public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFileName, [MarshalAs(UnmanagedType.U4)]Int32 nSize);
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(UInt32 dwDesiredAccsess, Int32 inherit, UInt32 dwProcessID);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr handle
public const long STANDARD_RIGHTS_REQUIRED = 0x000F0000L;
public const long SYNCHRONIZE = 0x00100000L;
public const long PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFFF);
public const long PROCESS_QUERY_INFORMATION = 0x0400;
protected static ProcessInfo FillProcessInfoEX(ProcessInfo pi)
{
IntPtr hWnd = OpenProcess((uint)PROCESS_ALL_ACCESS, 0, (uint)pi.iProcessID);
if (hWnd == IntPtr.Zero)
{
hWnd = OpenProcess((uint)PROCESS_QUERY_INFORMATION, 0, (uint)pi.iProcessID);
if (hWnd == IntPtr.Zero)
return pi;
}
StringBuilder path = new StringBuilder(1024);
GetModuleFileNameEx((IntPtr)hWnd, IntPtr.Zero, path, 1024);
pi.sFullFilePath = path.ToString();
System.Windows.Forms.MessageBox.Show(pi.sFullFilePath);
CloseHandle(hWnd);
return pi;
}
pi is a struct. This code works fine as long the build was ran within Visual Studio 2008. But if i run just with exe, pi.sFullFilePath has only garbage on all process id. What am i doing wrong? I am using XP
Thanks for help in advance
|
|
|
|
|
I don't think you can pass a StringBuilder when a string is expected:
StringBuilder path = new StringBuilder(1024);
GetModuleFileNameEx((IntPtr)hWnd, IntPtr.Zero, path, 1024);
So I don't see how it could work at all.
|
|
|
|
|
StringBuilder can be used for marshalling LPStr, LPTStr and LPWStr types.
|
|
|
|
|
I had a some new info
i modified like
SetLastError(0);
GetModuleFileNameEx((IntPtr)hWnd, IntPtr.Zero, path, 1024);
System.Windows.Forms.MessageBox.Show(GetLastError().ToString()); Get WinApi error code
I Got error code 5: ERROR_ACCESS_DENIED
How do i grand such privilages?
|
|
|
|
|
Hey
Is it possible to use HtmlDocument, withouth the WebBrowser control?
As you see, when the document is loaded in your WebBrowser control, you can fetch
some html elements such as links, images, etc.
But I want to set my own html in the HtmlDocument, and fetch the elements I want, withouth first
using the WebBrowser to navigate to an url.
My Idea is something like this:
HtmlDocument doc = webBrowser1.Document;
for (int i = 0; i < doc.GetElementsByTagName("a").Count; i++)
{
string url = doc.GetElementsByTagName("a")[i].GetAttribute("href");
}
But withouth have to use the WebBrowser control, and just set the html like this
doc.html = "<a href='link'>link ...</a>"
Please help me
Thanks in Advance
- opx
|
|
|
|
|
Yup, you just need to get a webpage first (simply as text):
m_Client = new WebClient();
string webPage = m_Client.DownloadString(@"http://www.codeproject.com");
Then you can write this string to a HtmlDocument using the Write method:
HtmlDocument doc = new HtmlDocument();
doc.Write(webPage);
...
for (int i = 0; i < doc.GetElementsByTagName("a").Count; i++)
{
string url = doc.GetElementsByTagName("a")[i].GetAttribute("href");
}
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hey, thanks allot for your reply, it worked exactly as I wanted!
But anyway, when I reopened c#, it gave me an error on "new Htmldocument();"
but il figure that out.
Thanks again!
|
|
|
|
|
Hello everyone!
My English is very poor,so if there are anything make u confused ,it's my fault.
I got a serious problem with CodeDom...here it is
I wrote a ScriptEngine with CodeDom,it can compile&run c# script file
that on the disk,something like this:
MyScriptEngine.cs
namespace HostApplication
{
public class MyScriptEngine
{
public void runScript(string fileOnDisk)
{
}
public int someElseMethod()
{
}
}
}
in the script file,i want to communication with Host Application
using System;
...
using HostApplication
public class scirpt
{
public void entryPoint()
{
MyScriptEngine.getInstance().someElseMethod();
}
}
it's possible to this?
any reply will be helpful!!
|
|
|
|
|
[Edit] Is your script class in a different namespace?[\Edit]
Yes, why not? Did you test it and got any exception?
When you're alone in the Dark, Fear will protect you...
modified on Thursday, November 6, 2008 1:59 PM
|
|
|
|
|
I already try:
1."using HostApplication" in script file -> ICodeCompiler report "can't find class or namespace..."
2.give script a namespace same with HostApplication namespace
namespace sameWithHostApplicationNamespace
{
public someclass
}
still can't access HostApplication ns class,CodeCompiler can't fint it
|
|
|
|
|
I'm using the Graphics.DrawString method to draw a string on a graphics context that has a transformation applied to it. Problem is, although the transformation gets the string to the proper location, it also scales the font size to something ridiculously large.
I know that you can force the Graphics methods to not scale line width if you create a Pen of width 0. Is there a similar way to prevent font size from being scaled?
(Not sure if this makes a difference, but the graphics context I'm drawing to is attached to a Bitmap object.)
modified on Thursday, November 6, 2008 9:50 AM
|
|
|
|
|
If you don't want to resize the text, do you really want to use a transformation? Why not just change the coordinates where you draw the text?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I have to check, the transformation doesn't involve scale does it? No?
Ok, the simplest method I can think of is to draw the string to a temporary buffer and the draw this buffer with the transformations you want.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
HI,
Can any one guide me how to run commands from a .Net Application developed in C# at Command prompt(i.E C:\>)
Any links on it would also be helpful
|
|
|
|