Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code> private string[,] GetImagesFromServerFolder() { IntPtr token; if ( !NativeMethods.LogonUser([Server_Login_Name], [Server_Location], [Server_Login_Password], NativeMethods.LogonType.NewCredentials, NativeMethods.LogonProvider.Default, out token)) { throw new Win32Exception(); } try { IntPtr tokenDuplicate; if (!NativeMethods.DuplicateToken( token, NativeMethods.SecurityImpersonationLevel.Impersonation, out tokenDuplicate)) { throw new Win32Exception(); } try { using (WindowsImpersonationContext impersonationContext = new WindowsIdentity(tokenDuplicate).Impersonate()) { /******************* CODE FROM HERE *******************/ List&lt;string&gt; files = new List&lt;string&gt;(Directory.GetFiles(_PHYSICAL SERVER LOCATION_)); return files; /******************* CODE TO HERE *******************/ } } finally { if (tokenDuplicate != IntPtr.Zero) { if (!NativeMethods.CloseHandle(tokenDuplicate)) { // Uncomment if you need to know this case. ////throw new Win32Exception(); } } } } finally { if (token != IntPtr.Zero) { if (!NativeMethods.CloseHandle(token)) { // Uncomment if you need to know this case. ////throw new Win32Exception(); } } } } </code></pre> <p><strong>This will then return a list of all the .pdf files and locations</strong><br> You can then sore that in a DB.</p> <p>Then, run through all the files in the list (In your main running method); </p> <pre><code>List&lt;string&gt; file = GetImagesFromServerFolder(); foreach (var s in file) { const string connStr = "INSERT INTO tblPdfLocations (location) VALUES (@location)"; //Store the connection details as a string string connstr = String.Format(@"SERVER=[LOCATION]; UID=[USERNAME]; pwd=[PASSWORD]; Database=[DATABASE]"); //Initialise the connection to the server using the connection string. _sqlConn = new SqlConnection(connstr); var sqlComm = new SqlCommand(connStr, _sqlConn) {CommandType = CommandType.Text}; sqlComm.Parameters.Add(new SqlParameter("@location", SqlDbType.VarChar, 50)).Value = s; sqlComm.ExecuteNonQuery(); _sqlConn.Close(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload