|
i want to remove folder in webserver. But Server is returning "550" error if folder is not empty.
i can delete files listing folder. But folders may includes sub folders. How can i get list of subfolders? Is there a simple way to delete non-empty folder?
<pre lang="vb">Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(ftp://ftp.server.com/), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(username, pass)
clsRequest.KeepAlive = True
clsRequest.Method = System.Net.WebRequestMethods.Ftp.RemoveDirectory
Dim response As FtpWebResponse = CType(clsRequest.GetResponse, FtpWebResponse)
response.Close()
|
|
|
|
|
ulasoc wrote: How can i get list of subfolders?
Follow the example here[^].
ulasoc wrote: Is there a simple way to delete non-empty folder?
AFAIK, there is no "deltree" in FTP.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
If i want a simple server to client communication as a background service on windows Os, that would only send ISP infor to a hosted domain, WHERE would i start? C# of VB.net or other? Which has an example or godd start?
Experience is the best teacher
|
|
|
|
|
You would not start with either, the language is not the issue. I'm not quite sure exactly what you are trying to do, but you may want to investigate the Windows Communication Foundation[^] for this sort of project.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Private Sub EncryptOrDecryptFile(ByVal jitfInputFile As String, _
ByVal jitfOutputFile As String, _
ByVal jitfKey() As Byte, _
ByVal jitfIV() As Byte, _
ByVal Direction As CryptoAction)
fsInput = New FileStream(jitfInputFile, FileMode.Open, FileAccess.Read)
fsOutPut = New FileStream(jitfOutputFile, FileMode.OpenOrCreate, FileAccess.Read)
fsOutPut.SetLength(0)
it give me an error saying fs.OutPut.SetLength(0)
Private Sub EncryptOrDecryptFile(ByVal jitfInputFile As String, _
ByVal jitfOutputFile As String, _
ByVal jitfKey() As Byte, _
ByVal jitfIV() As Byte, _
ByVal Direction As CryptoAction)
fsInput = New FileStream(jitfInputFile, FileMode.Open, FileAccess.Read)
fsOutPut = New FileStream(jitfOutputFile, FileMode.OpenOrCreate, FileAccess.Read)
fsOutPut.SetLength(0)
Getting an error when i click "Encrypt" says Stream Doest Not Support Writting. ..
inside the Buttom Click i have this
EncryptOrDecryptFile("C:\ProgramData\JITFapp\" & savexml, "C:\ProgramData\JITFapp\" & savexml + ".crypted", jitfKey, jitfIV, CryptoAction.ActionDencrypt)
Any Ideas
|
|
|
|
|
Your specifying FileAccess.Read[^] when opening the output file:
fsOutPut = New FileStream(jitfOutputFile, FileMode.OpenOrCreate, FileAccess.Read) Change FileAccess.Read to FileAccess.Write or FileAccess.ReadWrite and it should work.
fsOutPut = New FileStream(jitfOutputFile, FileMode.OpenOrCreate, FileAccess.Write)
0100000101101110011001000111001011101001
|
|
|
|
|
i didnt see that .. ok doing the change lets take a look it shud work perfect now =)
|
|
|
|
|
please reply fast.....for this question
|
|
|
|
|
public bool MyBool { get; set; }
Private _myBool As Boolean
Property MyBool() As Boolean
Get
Return _myBool
End Get
Set(ByVal Value As Boolean)
_myBool = Value
End Set
End Property
ankita.rose9 wrote: please reply fast.....for this question
..and where did you find the right to hurry me? Am I being paid by your company?
If you need this information "quick", I suggest studying; a property is a very basic construction, and studying makes sure that you can remember how to use it once you need it. Seriously, Google it, you'll find that it's nigh impossible to miss the examples.
Now, you're probably facing some other issue, like initializing this property correctly and/or getting it nicely in the propertygrid. If that's the case, change your question to reflect the actual problem.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hello -
In one hand, I have a form which contains a DataGridView. Clearly, the DGV is running on the UI thread.
In the other hand, I have an library object, which contains a DataTable. That datatable is updated by an internal System.Threading.Timer (not a form timer). A couple of times a second, a row is added to that table.
Once I set the DataSource of the DataGridView to be the DataTable of that library object, the DGV never redraws. The data is there, it just doesn't draw.
The problem is that the DataTable is being updated by a different thread than the UI thread (verified). Apparently, the "your data has changed" methods of the DGV are also being called on that other thread.
So: how do I avoid this? Since the update mechanisms are private to the DataSource/Binding mechanism, there is no clear place where I can use Invoke to sync the datatable with the UI thread, so I can cross the thread boundary safely.
I do own the library object. I am currently exposing the DataTable as a public object. Is there another way to get the data in the table to the DGV, in a way that crosses the thread boundary safely?
|
|
|
|
|
there may be a couple of options for you that i can think of straight away you can either Invoke the Add calls on the UI thread, or after everything has been added you can Invoke a mothod that triggers a refresh. I'm not very familiar with how this is done on winforms, but you can call invoke i believe on any control create on the UI thread.
so something like
dgv.Invoke(new Action(() =>
{
var toAdd = dt.NewRow();
dt.Rows.Add(toAdd);
}));
This may not be the neatest way but hopefully it should be a start for you. If you need a more tailored answer to your problem pop up a code sample and i'll take a look.
|
|
|
|
|
JoeRip wrote: So: how do I avoid this? Since the update mechanisms are private to the DataSource/Binding mechanism, there is no clear place where I can use Invoke to sync the datatable with the UI thread, so I can cross the thread boundary safely.
I do own the library object. I am currently exposing the DataTable as a public object. Is there another way to get the data in the table to the DGV, in a way that crosses the thread boundary safely?
MSDN has a how-to[^] on the subject. The annoying part is updating the grid if you have the new data, and this works best if the grid is in virtual mode[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks, but those articles assume that the non-Form thread knows about the Form, and call Form methods.
In my case, this library object does NOT know about the Form, and therefore cannot use Invoke to call Form methods. This is by design - the DataTable in the library object has no idea who is connecting to its DataSource, nor should it.
So there is no clear place where Invoke can be used, that I can tell. On the DataGridView's side, the RowsAdded event is simply not firing, because it's on the wrong thread. So the DGV is not getting updated.
I think it comes down to this: should I redesign the library object so that it takes a delegate to call after Rows.Add (seriously ugly)? Or should I not expose the DataTable directly, and look to find another method of making the DataTable's content available?
|
|
|
|
|
JoeRip wrote: I think it comes down to this: should I redesign the library object so that it takes a delegate to call after Rows.Add (seriously ugly)? Or should I not expose the DataTable directly, and look to find another method of making the DataTable's content available?
Nothing "ugly" about a CallBack method; that's the way to go if you don't want to be passing a pointer to your form to the thread.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Okay, here is a very simplified version of the problem. Note that the GrowingTable() class is normally in a separate assembly and namespace.
So - I can't just convert the Timer to a FormTimer, unless I pass the form itself to the GrowingTable class, which would be incredibly ugly.
And there's no clear place where I can Invoke, as there is no actual update function (that is hidden in the DataSource mechanism).
using System;
using System.Windows.Forms;
namespace dgv
{
public partial class Form1 : Form
{
DataGridView dgvMain = new DataGridView();
GrowingTable ra = new GrowingTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Controls.Add(dgvMain);
dgvMain.Dock = System.Windows.Forms.DockStyle.Fill;
dgvMain.Location = new System.Drawing.Point(0, 45);
dgvMain.DataSource = ra.itemTable;
ra.Start();
}
public class GrowingTable
{
public System.Data.DataTable itemTable;
private System.Threading.Timer myTimer = null;
public GrowingTable()
{
itemTable = new System.Data.DataTable();
myTimer = new System.Threading.Timer(this.AddRow, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
for (int i = 0; i < 11; i++)
{
itemTable.Columns.Add(new System.Data.DataColumn(i.ToString(), typeof(System.DateTime)));
}
}
public void Start()
{
myTimer.Change(0, 500);
}
private void AddRow(object state)
{
if (itemTable.Rows.Count < 50)
{
System.Data.DataRow dr = this.itemTable.NewRow();
for (int i = 0; i < 11; i++) { dr[i.ToString()] = DateTime.Now; }
this.itemTable.Rows.Add(dr);
}
else
{
myTimer.Dispose();
myTimer = null;
}
}
}
}
}
|
|
|
|
|
add this to Growing Table
public Action<Action> InvokeOnUI{get;set;}
in the AddRow method replace
this.itemTable.Rows.Add(dr);
with
if (InvokeOnUI!=null)
InvokeOnUI(()=>this.itemTable.Rows.Add(dr));
else
this.itemTable.Rows.Add(dr);
and don't forget to set it up using:
ra.InvokeOnUI = action => Invoke(action);
the sample i made is as follows if it helps
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Updater ud = new Updater();
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.DataSource = ud.Data;
ud.InvokeOnIU = action => Invoke(action);
}
private void button1_Click(object sender, EventArgs e)
{
Thread run = new Thread(ud.AddInBackGround);
run.Start();
}
}
public class Updater
{
public Updater()
{
Data = new DataTable();
Data.Columns.Add("Column 1");
Data.Columns.Add("Column 2");
Data.Columns.Add("Column 3");
}
public Action<Action> InvokeOnIU { get; set; }
public DataTable Data { get; set; }
public void AddInBackGround()
{
if (InvokeOnIU!=null)
{
var toAdd = Data.NewRow();
InvokeOnIU(()=>Data.Rows.Add(toAdd));
}
}
}
|
|
|
|
|
+5 for moving the dependency to a separate class, decoupling the form from the thread
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks! Very nice.
This is very similar to what I eventually settled on. Since GrowingTable() is actually in another (library) assembly completely, it can't have intimate knowledge of the UI's Form methods. And in fact, it may not be called from a Form at all.
So, I simply added an optional callBack delegate parameter to GrowingTables constructor, and I let the caller pass in a callBack function, to be called on each AddRow. That way, the caller can check NeedsInvoke on his side, and invoke the callBack over to the UI thread if necessary.
It's still ugly, but it's doable. I think the real solution is to not expose a DataTable directly, and handle the binding directly.
Actually, looking closer at what you've done here... this might be cleaner. Will play with it tomorrow.
Thanks!
|
|
|
|
|
I think this is not general enough for what I need. GrowingTable updates its table at arbitrary times. The caller (form) can't know when to call InvokeOnIU. If I understand the code above correctly, the form is only calling InvokeOnIU when it wants to.
How about this: GrowingTable will have a property, method and event:
bool fCallerNeedsUpdateOnItsOwnContext
void UpdateGTDataSource(GTUpdates updates)
event UpdateDataAgainstYourOwnContext
When GrowingTable needs to update its data, it will create a queue of updates (typically, rows to add, rows to replace other rows by id, or id's of rows to be deleted). If fCallerNeedsUpdateOnItsOwnContext is true, it will raise the UpdateDataAgainstYourOwnContext event, passing the queue of updates. Then the subscriber can call or Invoke GT.UpdateGTDataSource(updates) as it needs, to insure thread context safety.
If fCallerNeedsUpdateOnItsOwnContext is false, GrowingTable will simply execute the queue of updates itself.
What say you, coders?
|
|
|
|
|
the code sample i gave you puts the class in charge of refreshing the data in total control, the one call made in the UI is just letting the GrowingTable class know how to perform tasks in sync with the UI thread. after that stage has been performed the UI has no more involvement.
I'm glad you have found a solutino but the assumptin that the form is callint InvokeOnUI is not quite right.
|
|
|
|
|
Well, it works. Not sure about design quality, but it was better than the hacks I was using before. Thanks for all the help! Let me know if it sucks. Here's a sample which demonstrates the pattern; first the caller/form:
using System;
using System.Windows.Forms;
using GrowingDataTable;
namespace dgv
{
public partial class Form1 : Form
{
public DataGridView dgvMain;
public delegate void delEventHandler(object sender,
GrowingDataTable.UpdateDataTableOnYourThreadContextEventArgs e);
public GrowingDataTable gt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dgvMain = new DataGridView();
Controls.Add(dgvMain);
dgvMain.Dock = System.Windows.Forms.DockStyle.Fill;
gt = new GrowingDataTable();
gt.RaiseUpdateTableAgainstYourThreadContextEvent += new
EventHandler<GrowingDataTable.UpdateDataTableOnYourThreadContextEventArgs>
(gt_RaiseUpdateTableAgainstYourThreadContextEvent);
gt.UpdateDataTableOnCallerThreadContext = true;
dgvMain.DataSource = gt.itemTable;
gt.Start(3000, 1000);
}
void gt_RaiseUpdateTableAgainstYourThreadContextEvent(object sender,
GrowingDataTable.UpdateDataTableOnYourThreadContextEventArgs e)
{
if (InvokeRequired) {
Invoke(new
delEventHandler(gt_RaiseUpdateTableAgainstYourThreadContextEvent),
new object[] { sender, e}); }
else
{
if ((e.Updates != null) || (e.Updates.Count > 0))
{
gt.UpdateTableOnMyThreadContext(e.Updates);
}
}
}
}
}
Then the library class GrowingDataTable:
using System;
using System.Collections.Concurrent;
namespace GrowingDataTable
{
public class GrowingDataTable
{
public System.Data.DataTable itemTable;
public System.Threading.Timer myTimer = null;
private ConcurrentQueue<System.Data.DataRow> qUpdates = new
ConcurrentQueue<System.Data.DataRow>();
public GrowingDataTable()
{
itemTable = new System.Data.DataTable();
myTimer = new System.Threading.Timer(this.AddRows, null,
System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
for (int i = 0; i < 10; i++) {
itemTable.Columns.Add(new System.Data.DataColumn
(i.ToString(), typeof(System.DateTime))); }
}
public bool UpdateDataTableOnCallerThreadContext { get; set; }
public class UpdateDataTableOnYourThreadContextEventArgs : EventArgs
{
private ConcurrentQueue<System.Data.DataRow> qu;
public UpdateDataTableOnYourThreadContextEventArgs
(ConcurrentQueue<System.Data.DataRow> Qu)
{
qu = Qu;
}
public ConcurrentQueue<System.Data.DataRow> Updates
{
get { return qu; }
}
}
public event EventHandler<UpdateDataTableOnYourThreadContextEventArgs>
RaiseUpdateTableAgainstYourThreadContextEvent;
public void UpdateTableOnMyThreadContext(
ConcurrentQueue<System.Data.DataRow> Q)
{
System.Data.DataRow dr = null;
while (Q.TryDequeue(out dr))
{
if (dr != null)
{
itemTable.Rows.Add(dr);
}
}
}
public void Start(int delay, int interval)
{
myTimer.Change(delay, interval);
}
private void AddRows(object state)
{
if (itemTable.Rows.Count < 10)
{
System.Data.DataRow dr = this.itemTable.NewRow();
for (int i = 0; i < 11; i++) { dr[i.ToString()] = DateTime.Now; }
if (UpdateDataTableOnCallerThreadContext)
{
qUpdates.Enqueue(dr);
OnRaiseUpdateDataTableAgainstYourThreadContextEvent(new
UpdateDataTableOnYourThreadContextEventArgs(qUpdates));
}
else
{
this.itemTable.Rows.Add(dr);
}
}
else
{
myTimer.Dispose();
myTimer = null;
}
}
protected virtual void OnRaiseUpdateDataTableAgainstYourThreadContextEvent(
UpdateDataTableOnYourThreadContextEventArgs q)
{
EventHandler<UpdateDataTableOnYourThreadContextEventArgs> handler =
RaiseUpdateTableAgainstYourThreadContextEvent;
if (handler != null)
{
handler(this, q);
}
}
}
}
|
|
|
|
|
Hello Friends,,
well this is the situation im trying to simulate Keys but only when a proccess is actually running
this is what i have
Private Sub letter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles letter.Tick
Dim rprocess() As System.Diagnostics.Process = Process.GetProcessesByName("Test.exe")
If System.IO.File.Exists("C:\test\Listener.txt") Then
Else
System.IO.File.Create("C:\Test\Listener.txt")
End If
If rprocess.Length = 1 Then
ElseIf (GetAsyncKeyState(Keys.A)) Then
Dim ReadIt As String = System.IO.File.ReadAllText("C:\Test\Listener.txt")
System.IO.File.WriteAllText("C:\Test\Listener.txt", ReadIt & "A")
End If
End Sub/pre>
but is stil reading the "A" even if the proccess is off or not present .. HELP !!
|
|
|
|
|
SORRY WORLD .. found the problem =)
if anyone tries then is
if rprocess.length = 1 then
getasynckeystate(keys.a)
remove elseif and the "()"
|
|
|
|
|
Hi Everyone,
I did a search on capturing screen shots in vb.net and I was wondering if there is a straight forward way to capture the active window? Or do I need to first get the handle of the active window, get the position and size and then capture it? I do not want to use any type of sendkeys method or use the clipboard. I want to save it to jpg format.
Thanks!
Done so far but its capturing the entire window is
Module patternAload
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Integer
Const SRCCOPY As Integer = &HCC0020
Private oBackground As Bitmap
Private FW, FH As Integer
Public Sub CaptureScreen()
Dim hSDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim r As Integer
Dim fgw As Long = GetForegroundWindow()
hSDC = CreateDC("DISPLAY", "", "", "")
hMDC = CreateCompatibleDC(hSDC)
FW = GetDeviceCaps(hSDC, 8)
FH = GetDeviceCaps(hSDC, 10)
hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
hBMPOld = SelectObject(hMDC, hBMP)
r = BitBlt(hMDC, 40, 40, FW, FH, hSDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
r = DeleteDC(hSDC)
r = DeleteDC(hMDC)
oBackground = Image.FromHbitmap(New IntPtr(hBMP))
DeleteObject(hBMP)
End Sub
|
|
|
|
|
I suspect that the following code should help:
<DllImport("user32.dll")> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function GetWindowRect(hWnd As IntPtr, ByRef lpRect As RECT) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll", ExactSpelling := True, CharSet := CharSet.Auto)> _
Private Shared Function SetForegroundWindow(hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<StructLayout(LayoutKind.Sequential)> _
Public Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Public Shared Sub CaptureWindow(fileName As String, format As ImageFormat)
Dim hWnd As IntPtr = GetForegroundWindow()
If hWnd = IntPtr.Zero Then
Return
End If
Dim srcRect As RECT
If Not GetWindowRect(hWnd, srcRect) Then
Return
End If
Dim width As Integer = srcRect.Right - srcRect.Left
Dim height As Integer = srcRect.Bottom - srcRect.Top
Using bmp As New Bitmap(width, height)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(srcRect.Left, srcRect.Top, 0, 0, New Size(width, height), CopyPixelOperation.SourceCopy)
bmp.Save(fileName, format)
End Using
End Using
End Sub If you want to do it in C#, the same code would look like this:
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public static void CaptureWindow(string fileName, ImageFormat format)
{
IntPtr hWnd = GetForegroundWindow();
if (hWnd == IntPtr.Zero) return;
RECT srcRect;
if (!GetWindowRect(hWnd, out srcRect)) return;
int width = srcRect.Right - srcRect.Left;
int height = srcRect.Bottom - srcRect.Top;
using (Bitmap bmp = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(srcRect.Left, srcRect.Top, 0, 0,
new Size(width, height), CopyPixelOperation.SourceCopy);
bmp.Save(fileName, format);
}
}
}
|
|
|
|
|