From what I have read its not possible to find a clients local printer using modern browsers for security reasons. I have a few conditions that might make that answer different.
I am trying to get clients local printers from within a company network. So this isnt published 'outside'
I thought several years ago Microsoft released a small version of .Net that could be run from the clients browser. If so and its still around I wonder if that could inspect clients local printer.
Thanks
One way to give the appearance of retrieving the clients printers is to run a server side application in the same network with the same access permissions. Silverlight may be able to do it. I have no experience with it unfortunately.
Check here: Get list of network printers silverlight
This ended up being a lot of work with little information because nearly all my searches on the internet for a solution assumed we want to get the printers of the client from the browser. We want to find such information it via the Network.
The solution ended up being with DirectorySearch and the like. here is the code with some privacy stuff removed. Its in a POF state so it might have some not so great syntax
Dim list As New List(Of String)
Dim listtemp As New List(Of String)
Dim resultCollection As SearchResultCollection
Dim computer_name As String = System.Net.Dns.GetHostEntry(Request.ServerVariables("remote_addr")).HostName.Replace(".ourcompany.com", "").ToLower 'clients machine name
Dim dirEntry As New DirectoryEntry("LDAP://DC=OURCOMPANY, DC=com")
Dim dirSearcher As New DirectorySearcher(dirEntry)
dirSearcher.Filter = "objectCategory=printQueue"
dirSearcher.PropertyNamesOnly = True
dirSearcher.PropertiesToLoad.Add("Name")
dirSearcher.SearchScope = SearchScope.Subtree
resultCollection = dirSearcher.FindAll()
For Each sresult As SearchResult In resultCollection
If sresult.GetDirectoryEntry.Name.ToLower.Contains(computer_name) Then
list.Add(sresult.GetDirectoryEntry.Name.ToLower.Substring(3).Replace(computer_name + "-", ""))
End If
Next
Related
I am currently tasked with moving one of our older bits of software to a new server. The old server is running 2008 and the new server is on 2019. The code is a mixture of ASP and ASP.NET, both using VB. Unfortunately, I'm a C# developer and my VB knowledge is slight.
The main bit of the code is the older and is all in ASP and works fine on the new server. For a particular set of customers there is an add-on that is more recent and uses ASP.NET. For the new section of code to get the details of the logged in user it uses the code given in this answer. Unfortunately it seems like it is this bit of code that is failing.
We have this bit of code in our site.master.vb
ctx1 = ctx.Request.Url.Scheme
ctx2 = ctx.Request.Url.Host
dom = ctx1 + "://" + ctx2
Dim ASPRequest As HttpWebRequest = WebRequest.Create(New Uri(dom + "/arc/asp2netbridge.asp?sessVar=" + sessionValue))
ASPRequest.ContentType = "text/html"
ASPRequest.Credentials = CredentialCache.DefaultCredentials
If (ASPRequest.CookieContainer Is Nothing) Then
ASPRequest.CookieContainer = New CookieContainer()
End If
The asp2netbridge.asp file is stored in the directory one up from the directory that contains the code and the directory structure looks the same on both servers. The contents of the as2netbridge file are the the same as in the example code linked above with the addition of some extra comments.
It then calls a Stored Procedure on our database with the customer ID from session that should return the customer details as XML, but instead we get a 'Root Element is missing' Error. If I change the Stored Procedure to hard code the customer ID in it, rather than as a parameter then it works as expected.
Is there anything that I need to install on our server to get the system working correctly? Or is there anything else I need to do to get it to work?
I need to change dataset connectionstrings to point to different DBs at run time.
I've looked at a number of solutions however they all seem to be related to WinForms or web application projects or other technology slightly different than what I'm using, so I haven't figured out how apply them.
The application is like a discussion. It's a web site project based on code originally written under VS2005, and there's no budget (or personal talent!) for major changes at this time. The app is written in vb.net; I can understand answers in c#. I'm working in VS2013.
The app has three typed datasets pointing to one MDF, call it "MainDB.mdf". There are dozens of tableadapters among the three datasets.
I'm going to deploy the app it as an "alpha/demo" version. I would like to use the same code base for all users, and a separate physical version of MainDB for each user, to reduce chances that the users crash each other.
The initial demo access URL will contain query string information that I can use to connect the user with the right physical database file. I should be able to identify the database name and thus the connection string parameters from the query string information (probably using replace on a generic connection string). If necessary I could use appsettings to store fully formed connection strings, however, I would like to avoid that.
I would like to be able to change the connection strings for all the datasets at the time that the entry point pages for the app are accessed.
Changing the tableadapter connection strings at each instantiation of the tableapters would require too much code change (at least a couple of hundred instantiations); I'd just make complete separate sites instead of doing that. That's the fall back position if I can't dynamically change the connectionstrings at runtime (or learn some other way to make this general scheme work).
Any suggestions on how to approach this would be appreciated.
Thanks!
UPDATE: Per comments, here is a sample instantiation of tableadapter
Public Shared Sub ClearOperCntrlIfHasThisStaff( _
varSesnID As Integer, varWrkprID As Integer)
Dim TA As GSD_DataSetTableAdapters.OPER_CNTRLTableAdapter
Dim DR As GSD_DataSet.OPER_CNTRLRow
DR = DB.GetOperCntrlRowBySesnID(varSesnID)
If IsNothing(DR) Then
Exit Sub
End If
If DR.AField = varWrkprID Then
DR.AField = -1
TA.Update(DR)
DR.AcceptChanges()
End If
End Sub
UPDATE: Below is the test code I tried in a test site to modify the connectionString in a single instantiation of a tableadapter. It feeds a simple gridview. I tried calling this from Page_Load, Page_PreLoad, ObjectDataSource_Init, and Gridview_Databind. At the concluding response.writes, the wrkNewConnString looks changed to TestDB2, and the TA.Connection.ConnectionString value looks changed to TestDB2, but the displayed gridview data is still from TestDB1. Maybe it needs to be called from somewhere else?
Sub ChangeTableAdapter()
Dim wrkNewConnStr As String = ""
Dim wrkSel As Integer
wrkSel = 2
wrkNewConnStr = wrkNewConnStr & "Data Source=.\SQLEXPRESS;"
wrkNewConnStr = wrkNewConnStr & "AttachDbFilename=D:\9000_TestSite\App_Data\TESTDB1.MDF;Integrated Security=True;User Instance=True"
Select Case wrkSel
Case 1
wrkNewConnStr = wrkNewConnStr.Replace("TESTDB1", "TESTDB1")
Case 2
wrkNewConnStr = wrkNewConnStr.Replace("TESTDB1", "TESTDB2")
Case 3
wrkNewConnStr = "Data Source=localhost; Initial Catalog=test01;"
wrkNewConnStr = wrkNewConnStr & " User ID=testuser1; Password=testuserpw1"
End Select
Try
Dim TA As New DataSetTableAdapters.NamesTableAdapter
TA.Connection.ConnectionString = wrkNewConnStr
Response.Write("1 - " & wrkNewConnStr)
Response.Write("<br/>")
Response.Write("2 - " & TA.Connection.ConnectionString)
Catch ex As Exception
Dim exmsg As String = ex.Message
Response.Write(exmsg)
End Try
End Sub
The connection string:
<add name="TestDB1ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=D:\9000_TestSite\App_Data\TESTDB1.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
UPDATE: the following post has lots of solutions, however, they seem to focus on web application projects, that have a project file with settings, which this web site project does not.
link with possible solutions
UPDATE: this next link was brought to my attention, and in working on it I did get it to work, however, it still relies either on having a web application project (with project file) or modifying each table adapter as they are instantiated. So, while I'm not going to implement it, I believe that is the technical answer.
modifying connection strings
sorry if this answer is too late, but I have exactly the same problem and eventually came up with a solution using Reflection.
My solution was to "save" a new default value for the connection string in the settings at run time, which means any further use of the table adapter uses the the new connection string.
It should be noted the term "save" is misleading as the new value is lost when the application closes.
Have tested and worked perfectly.
public void ChangeDefaultSetting(string name, string value)
{
if (name == null)
throw new ArgumentNullException("name");
if (value == null)
throw new ArgumentNullException("value");
Assembly a = typeof({Put the name of a class in the same assembly as your settings class here}).Assembly;
Type t = a.GetType("{Put the full name of your settings class here}");
PropertyInfo propertyInfo = t.GetProperty("Default");
System.Configuration.ApplicationSettingsBase def = propertyInfo.GetValue(null) as System.Configuration.ApplicationSettingsBase;
//change the "defalt" value and save it to memory
def[name] = value;
def.Save();
}
Searched, but couldn't find a good answer.
I have an ASP.NET application that I am developing. I'm using session variables within the app.
In Firefox & Chrome, they all work.
But in IE (ver 9), there's one variable that's not working. I'm not sure if it's a storage or a retrieval (or both) at this point. The variable in question that I'm storing is a List(T) type. It's the only one of it's kind that I'm using. Can't help but think there's a correlation there.
One other old post mentioned the possibility that cache is causing the problem, but I didn't understand the answer very well.
P.S. If possible, please post any code samples in VB. Sometimes I can read the C# and translate it, and sometimes not.
Dim Rec_IDs As New List(Of String)
Rec_IDs = Session("Rec_IDs")
and
Dim Rec_IDs As New List(Of String)
Dim Rec_ID As Int32
Rec_IDs = Session("Rec_IDs")
For Each Row As GridViewRow In gvParts.Rows
If CType(Row.FindControl("chkSelect"), CheckBox).Checked Then
Rec_ID = gvParts.DataKeys(Row.RowIndex).Value
If Not Rec_IDs.Contains(Rec_ID) Then
Rec_IDs.Add(Rec_ID)
End If
CType(Row.FindControl("chkSelect"), CheckBox).Checked = False
End If
Next
Session("Rec_IDs") = Rec_IDs
lblCount.Text = String.Format("You have {0} records selected", Rec_IDs.Count.ToString)
Other answer: Session Variable not working in Internet Explorer, but works fine in Firefox / Chrome
First check your cookies are enabled or not in your browser. If the cookies are blocked that will be the problem with IE
Also have a look at
Cookieless ASP.NET,
ASP.NET State Management Overview,Difference between browser session and asp.net session
i am not a programmer, but i can frankenstein code snippets with sufficient proficiency that if, by the grace of a few good souls, i could come across some sample ASP code that acts as a GUI to the ms index server, i could certainly make it work and look good.
if anyone can offer any help, i would do a backflip. but i won't put it on youtube. there's enough faceplant videos out there.
summary: does anyone know where i can find index server asp pages? the more complete, the better. snippets are more than welcome.
btw: io tagged this as sharepoint since this is so similar. some moss admins will certainly be able to lend me a hand!
How about some samples from CodeProject? Would that suit your needs? I'm sorry I can't offer any more specific help without knowing more details and what you are trying to do.
Microsoft Index Server class for ASP (classic ASP)
Your free search engine – Microsoft Indexing Server
To talk to an index server catalogue from asp.net you can use an ole db connection object.
OleDbConnection conn = new OleDbConnection("Provider=MSIDXS;Integrated Security .=;Data Source=" + catalogName);
cmdQuery = new OleDbCommand(query, conn);
Where catalogName is the name of the catalog on your machine you are querying. And query is a string containing the index query you are using.
//Get reader
rQuery = cmdQuery.ExecuteReader(CommandBehavior.CloseConnection);
//Create dataset and load values from reader into it
dataQuery = new DataSet("IndexResults");
dataQuery.Load(rQuery, LoadOption.OverwriteChanges, new string[] { "" });
//Return the first table which will be the results from the query
results = dataQuery.Tables[0].Copy();
Don't forget to dispose of the connection and reader in a finally statement :)
Index query itself is very similar to SQL - you can also set properties in the query to be used as aliases so it is easier to read.
I have two webparts in two different webpart zones. They provide a Master/Details scenario using gridviews. They are defined using static connections. Initially this works great.
As soon as I close one of the webparts I get the message "You are about to close the webpart. It is currently providing data to other webparts, and these connections will be deleted if this webpart is closed. Click OK to continue.
This in itself is fine so I click close and my part closes. However when I open the catalog zone and re-add the webpart (which gets added fine) the connection between the parts is broken (as described by the message).
However my webpart connection in my HTML is still visible. I can only assume it uses the ASPNET membership or other to remember the ID of the connection and not to enable it.
My question is how do I re-enable the connection in code or other!?
Thanks.
OK I have solved my issue. I added the following into WebpartManager.WebpartAdded()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim wp1 As WebPart = zoneDiaryTopLeft.WebParts("Ucl_Diary_Summary1")
Dim wp2 As WebPart = zoneDiaryTopRight.WebParts("Ucl_DiaryAwaitingReview1")
Dim providerConnectionPoint As ProviderConnectionPoint = _
WebPartManager1.GetProviderConnectionPoints(wp1)("IMessageProvider")
Dim consumerConnectionPoint As ConsumerConnectionPoint = _
WebPartManager1.GetConsumerConnectionPoints(wp2)("IMessageConsumer")
Dim returnValue As WebPartConnection
returnValue = WebPartManager1.ConnectWebParts(wp1, providerConnectionPoint, wp2, consumerConnectionPoint)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
All said, how does it know/store the connection that was removed and remember to NOT allow that to be active!? It would be much easier if I could stop the connection being removed or re-enable it. I know dynamic connections are an option but I dont want users having this ability as they having a hard enough job understanding the fact you can drag a webpart around the screen. Connections are rocketscience to them.