environment.username property

S

steve

i posted a message the other day about a problem i'm having with the
enivornment.username property. Turns out i was a bit off on the
nature of the problem. so i'm trying again.

Like many of you, i have code behind my infopath form that uses
environment.username to determine the name of the person using the
form. This code has been running for years, with dozens of users.
It's aways been fine.

Now - for one particular user - the code no longer works. the
environment.username appears to be blank.

if I logon to Windows as this user, go to the command prompt, and
issue the "set" command, it appears that the appropriate value is
there (it shows USERNAME=janet.doe).

Yet, in my infopath form the following line doesn't work. It doesn't
even execute the Alert statement. Doesn't get an error, but just
skips the line without doing the Alert. like i said, for all others
on the project it works fine.


testName = Environment.UserName
thisXDocument.UI.Alert("Test - Who am I? " & testName)

i also have a select statement: Select Case Environment.UserName
that doesn't work for this user. it just seems to skip the statement
all together. doesn't fall into the Case Else branch like i would
expect of there wre no value in UserName.



Anybody have any idea? i'm drawing a blank.

thanks
 
S

Shiva (GGK Tech)

Hello,

Do you have import the library of ‘System’ class in your code? Can you check
the below line for user name,

try
{
string userName = System.Environment.UserName
}
catch(Exception ex)
{
thisXDocument.UI.Alert(ex.Message);
}

Can you tell us what the value of username is after executing above line?
 
S

steve

Hello,

Do you have import the library of ‘System’ class in your code? Can you check
the below line for user name,

try
{
string userName = System.Environment.UserName}

catch(Exception ex)
{
thisXDocument.UI.Alert(ex.Message);

}

Can you tell us what the value of username is after executing above line?

--
Shivahttp://www.ggktech.com













- Show quoted text -

thanks for everybody's response!

putting the "try block" in produced some results. awesome. I'm
getting the following error:

"Request for the permission of type
"System.Security.Permissions.EnvironmentPermission,
mscorlib,Version=2.0.0.0,Culture=neutral,PublicToken=b77a5c561934e089'
failed.

Like i said, only this one user gets this error. it works for
everybody else on the project. (and it did work for this user too,
until recently).
It doesn't seem to be a setting on her pc - if i have somebody else
logon with her id on their machine i get the same error.
any ideas on what's causing it?


thanks again!
 
S

steve

thanks for everybody's response!

putting the "try block" in produced some results.  awesome.  I'm
getting the following error:

"Request for the permission of type
"System.Security.Permissions.EnvironmentPermission,
mscorlib,Version=2.0.0.0,Culture=neutral,PublicToken=b77a5c561934e089'
failed.

Like i said, only this one user gets this error.  it works for
everybody else on the project.  (and it did work for this user too,
until recently).
It doesn't seem to be a setting on her pc - if i have somebody else
logon with her id on their machine i get the same error.
any ideas on what's causing it?

thanks again!- Hide quoted text -

- Show quoted text -

the user with the problem was upgrade to IE 7. everybody else on the
project still uses IE 6. I wonder if that has something to do with
it. ? I don't see any obvious difference in the settings, at least
not yet.
 
S

steve

Hello,

Is that statement is executed successfully? Are you getting any error while
executing the statement?

After executing try block are you reaching catch block also? Then what is
the alert you are getting with ex.Message?

--
Shivahttp://www.ggktech.com







- Show quoted text -

the error has changed slightly now. For some reason, i can now read
the evironment variable ok (don't know why, maybe a changed a setting,
but hey, i'll take it).

Now, when i try to submit an email:



Try
thisXDocument.UI.Alert("about to submit the email")
oEmail.Submit()
thisXDocument.UI.Alert("submitted the email")
Catch ex2 As Exception
thisXDocument.UI.Alert("there was a problem submitting
the email !!!!!!!!!!!!!!!!")
thisXDocument.UI.Alert(ex2.Message)
End Try

i get an error. I get the Alert "there was a problem...." .
Curiously, I don't get the second Alert (ex2.Message).

Next, I just get a message generated by Infopath that says "InfoPath
cannot submit the form". Like I said, this only happens with one
particular user. Even one else is fine.
Later in the code, it saves the form to SharePoint. that works fine!

thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top