Click here to Skip to main content
12,240,300 members (66,499 online)
   

C#

 
GeneralRe: How do they do this when copying files? Pin
PHS2411-May-13 22:17
memberPHS2411-May-13 22:17 
GeneralRe: How do they do this when copying files? Pin
Pete O'Hanlon2-May-13 1:01
protectorPete O'Hanlon2-May-13 1:01 
GeneralRe: How do they do this when copying files? Pin
PHS2412-May-13 1:57
memberPHS2412-May-13 1:57 
GeneralRe: How do they do this when copying files? Pin
Pete O'Hanlon2-May-13 2:00
protectorPete O'Hanlon2-May-13 2:00 
GeneralRe: How do they do this when copying files? Pin
PHS2412-May-13 2:23
memberPHS2412-May-13 2:23 
AnswerRe: How do they do this when copying files? Pin
Abhinav S2-May-13 0:36
mvpAbhinav S2-May-13 0:36 
Questionmodify C# 2008 desktop application Pin
classy_dog1-May-13 17:47
memberclassy_dog1-May-13 17:47 
AnswerRe: modify C# 2008 desktop application Pin
Pete O'Hanlon1-May-13 19:54
protectorPete O'Hanlon1-May-13 19:54 
Questionunexpected end of file Pin
miket2144123451-May-13 14:54
membermiket2144123451-May-13 14:54 
AnswerRe: unexpected end of file Pin
Freak301-May-13 23:26
memberFreak301-May-13 23:26 
AnswerRe: unexpected end of file Pin
Eddy Vluggen2-May-13 1:30
mvpEddy Vluggen2-May-13 1:30 
QuestionProblem while exporting a aspx page to pdf Pin
Member 100216341-May-13 0:20
memberMember 100216341-May-13 0:20 
AnswerRe: Problem while exporting a aspx page to pdf Pin
Jasmine25011-May-13 9:40
memberJasmine25011-May-13 9:40 
QuestionBest practice to select and copy a file to a remote location? Pin
matleeds1-May-13 0:07
membermatleeds1-May-13 0:07 
I have a requirement where when a button is clicked the app connects to a remote pc and the user can browse to a folder on the c drive then copy a file to their pc (not on a LAN but a remote location)

When using Remote desktop connection the details are (for example)
Computer: abcd.dyndns.org:1234
Username: bob2\apple
Password: password

After doing a bit of research using WMI or Impersonation seems the best options. Here's where I'm at with the Impersonation approach..

[DllImport("advapi32.DLL", SetLastError=true)]
        public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType,
            int dwLogonProvider, ref IntPtr phToken);
 
private void button4_Click(object sender, EventArgs e)
        {
            WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
            WindowsImpersonationContext wic = null;
            try
            {
                IntPtr admin_token = new IntPtr();
               
                if (LogonUser("bob2\apple", "abcd.dyndns.org:1234","password",9, 0, ref admin_token) != 0)
                {   
                    wic = new WindowsIdentity(admin_token).Impersonate();
 
                    // NOT SURE ABOUT THIS BIT.....
                    File.Copy(@"", @"",
                        true);
                    MessageBox.Show("Copy Succeeded");
                }
                else
                {
                    MessageBox.Show("Copy Failed");
                }
             }
            catch(Exception se)
            {
                int ret = Marshal.GetLastWin32Error();
                MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString());
                MessageBox.Show(se.Message);
            }
            finally
            {
                if (wic != null)
                    wic.Undo();
            }
           
        }

thanks
Mat

AnswerRe: Best practice to select and copy a file to a remote location? Pin
Jasmine25011-May-13 9:37
memberJasmine25011-May-13 9:37 
AnswerRe: Best practice to select and copy a file to a remote location? Pin
jschell1-May-13 9:41
memberjschell1-May-13 9:41 
Questionpassword creation in c# winform Pin
Member 1002123530-Apr-13 19:39
memberMember 1002123530-Apr-13 19:39 
AnswerRe: password creation in c# winform Pin
Richard MacCutchan30-Apr-13 22:42
mvpRichard MacCutchan30-Apr-13 22:42 
AnswerRe: password creation in c# winform Pin
GuyThiebaut1-May-13 3:14
memberGuyThiebaut1-May-13 3:14 
Questionhow to get the value of a control in a process which start with Process.start Pin
Member 1001614230-Apr-13 19:11
professionalMember 1001614230-Apr-13 19:11 
AnswerRe: how to get the value of a control in a process which start with Process.start Pin
Richard MacCutchan30-Apr-13 22:37
mvpRichard MacCutchan30-Apr-13 22:37 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Member 100161421-May-13 15:33
professionalMember 100161421-May-13 15:33 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Richard MacCutchan1-May-13 22:02
mvpRichard MacCutchan1-May-13 22:02 
QuestionSaving DrawLine to Image: SOLVED Pin
Member 792126830-Apr-13 4:34
memberMember 792126830-Apr-13 4:34 
AnswerRe: Saving DrawLine to Image Pin
Eddy Vluggen30-Apr-13 5:05
mvpEddy Vluggen30-Apr-13 5:05 
GeneralRe: Saving DrawLine to Image Pin
Member 792126830-Apr-13 6:11
memberMember 792126830-Apr-13 6:11 
AnswerRe: Saving DrawLine to Image Pin
Kenneth Haugland30-Apr-13 5:42
professionalKenneth Haugland30-Apr-13 5:42 
GeneralRe: Saving DrawLine to Image Pin
Member 79212681-May-13 1:46
memberMember 79212681-May-13 1:46 
AnswerRe: Saving DrawLine to Image: SOLVED Pin
Member 79212681-May-13 5:39
memberMember 79212681-May-13 5:39 
QuestionThe performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:30
professionalRob Philpott30-Apr-13 4:30 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Eddy Vluggen30-Apr-13 5:01
mvpEddy Vluggen30-Apr-13 5:01 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 5:31
professionalRob Philpott30-Apr-13 5:31 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
harold aptroot30-Apr-13 9:33
memberharold aptroot30-Apr-13 9:33 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 9:44
professionalRob Philpott30-Apr-13 9:44 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
harold aptroot30-Apr-13 9:54
memberharold aptroot30-Apr-13 9:54 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Eddy Vluggen30-Apr-13 10:42
mvpEddy Vluggen30-Apr-13 10:42 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 5:03
professionalSimon_Whale30-Apr-13 5:03 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 5:24
professionalRob Philpott30-Apr-13 5:24 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 5:46
professionalSimon_Whale30-Apr-13 5:46 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 5:57
professionalRob Philpott30-Apr-13 5:57 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 6:32
professionalSimon_Whale30-Apr-13 6:32 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Freak3030-Apr-13 5:36
memberFreak3030-Apr-13 5:36 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Dave Kreskowiak30-Apr-13 6:17
mvpDave Kreskowiak30-Apr-13 6:17 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Pete O'Hanlon30-Apr-13 7:38
protectorPete O'Hanlon30-Apr-13 7:38 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 7:49
professionalRob Philpott30-Apr-13 7:49 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale1-May-13 0:41
professionalSimon_Whale1-May-13 0:41 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Richard Deeming30-Apr-13 8:24
professionalRichard Deeming30-Apr-13 8:24 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 8:54
professionalRob Philpott30-Apr-13 8:54 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
jschell30-Apr-13 10:54
memberjschell30-Apr-13 10:54 
QuestionCrystal Report without preview print is not working in published file Pin
swathipd30-Apr-13 1:34
memberswathipd30-Apr-13 1:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 29 Apr 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid