Showing posts with label supposed. Show all posts
Showing posts with label supposed. Show all posts

Saturday, March 31, 2012

Trim URL String

I am trying to populate selected values from a drop-down list into URL params. I have the below code, which is supposed to remove the trailing comma from the end of the URL, but it does not seem to be working. Does anyone see anything obviously incorrect?

Thanks in advance.
----------

if (lbxWFTemplate.Visible ==true)

{

strURL +="WFTemplate=";

foreach (ListItem liWFTemplatein lbxWFTemplate.Items)

{

if (liWFTemplate.Selected)

{

strURL += liWFTemplate.Value.ToString() +",";

}

}

strURL.TrimEnd(",".ToCharArray());

I actually figured this out right after I posted. Trimend() returns a string, so the following was changed, and the code works as expected now:
strURL = strURL.TrimEnd(",".ToCharArray());

Wednesday, March 28, 2012

Trouble creating new directory

Hello,
I am using c# and running a site that is on a shared
host. The code in question is supposed to create a new
directory that is coming out of a text box.

It works fine on my computer, but I get the following
stack trace:

System.IO.DirectoryNotFoundException: Could not find a
part of the path "D:\". at System.IO.__Error.WinIOError
(Int32 errorCode, String str) at
System.IO.Directory.InternalCreateDirectory(String
fullPath, String path) at System.IO.DirectoryInfo.Create
() at testapps.createdir.CreateSubDirectory(String direc)

The code to create is as follows:

public bool CreateSubDirectory(string direc)
{
bool returnStatus = false;
DirectoryInfo di = new DirectoryInfo(@dotnet.itags.org.direc);
if(di.Exists)
{
Trace.Write("Directory exists " +
di.FullName);
this.Label1.Text = "Directory exists";
}
else
{
Trace.Write("Directory does not exist " +
di.FullName);
this.Label1.Text = "Directory does not
exists";
try
{
di.Create();
if(di.Exists)
{
Trace.Write("Directory exists
after creating it");
this.Label1.Text += "Directory
exists after creating it";
}
}
catch(Exception ex)
{
this.Label1.Text += "Error trying to
create directory that did not exist " + ex.ToString();
Trace.Write("Error creating directory
that does not exist " + ex);
}
}
return returnStatus;
}

Any ideas or suggestions, it works great on my local
machine?

Sheldon Cohen
shelman2@dotnet.itags.org.hotmail.comThis may be a misnomer of an error, but I think the root of your problem (no
pun intended) is that you don't have permissions to get at data outside of
your configured directory on the Host server. Imagine if you could - you can
probe the entire server and scavage all the other site's files which would
be a bit of a security risk to say the least.

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
-----------
Making waves on the Web

"Sheldon Cohen" <shelman2@.hotmail.com> wrote in message
news:2db7501c394e2$8cb6dd20$a601280a@.phx.gbl...
> Hello,
> I am using c# and running a site that is on a shared
> host. The code in question is supposed to create a new
> directory that is coming out of a text box.
> It works fine on my computer, but I get the following
> stack trace:
> System.IO.DirectoryNotFoundException: Could not find a
> part of the path "D:\". at System.IO.__Error.WinIOError
> (Int32 errorCode, String str) at
> System.IO.Directory.InternalCreateDirectory(String
> fullPath, String path) at System.IO.DirectoryInfo.Create
> () at testapps.createdir.CreateSubDirectory(String direc)
> The code to create is as follows:
> public bool CreateSubDirectory(string direc)
> {
> bool returnStatus = false;
> DirectoryInfo di = new DirectoryInfo(@.direc);
> if(di.Exists)
> {
> Trace.Write("Directory exists " +
> di.FullName);
> this.Label1.Text = "Directory exists";
> }
> else
> {
> Trace.Write("Directory does not exist " +
> di.FullName);
> this.Label1.Text = "Directory does not
> exists";
> try
> {
> di.Create();
> if(di.Exists)
> {
> Trace.Write("Directory exists
> after creating it");
> this.Label1.Text += "Directory
> exists after creating it";
> }
> }
> catch(Exception ex)
> {
> this.Label1.Text += "Error trying to
> create directory that did not exist " + ex.ToString();
> Trace.Write("Error creating directory
> that does not exist " + ex);
> }
> }
> return returnStatus;
> }
> Any ideas or suggestions, it works great on my local
> machine?
> Sheldon Cohen
> shelman2@.hotmail.com
Thanks, that makes sense. I have contacted my host and they do not have
a clue what to do. Any suggestions of how I could get this working?

Thanks,

Sheldon Cohen

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks, that makes sense. I have contacted my host and they do not have
a clue what to do. Any suggestions of how I could get this working?

Thanks,

Sheldon Cohen

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
What do you need access to the root for?

Basically your domain probably runs under a specific user account they've
set up for you. That username needs rights to access the directories you
want to access. Since htey lock it down they should have a clue what to do
<g>...

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
-----------
Making waves on the Web

"Sheldon Cohen" <shelman2@.hotmail.com> wrote in message
news:uMQNpQSlDHA.3504@.TK2MSFTNGP11.phx.gbl...
> Thanks, that makes sense. I have contacted my host and they do not have
> a clue what to do. Any suggestions of how I could get this working?
> Thanks,
> Sheldon Cohen
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
What do you need access to the root for?

Basically your domain probably runs under a specific user account they've
set up for you. That username needs rights to access the directories you
want to access. Since htey lock it down they should have a clue what to do
<g>...

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
-----------
Making waves on the Web

"Sheldon Cohen" <shelman2@.hotmail.com> wrote in message
news:uMQNpQSlDHA.3504@.TK2MSFTNGP11.phx.gbl...
> Thanks, that makes sense. I have contacted my host and they do not have
> a clue what to do. Any suggestions of how I could get this working?
> Thanks,
> Sheldon Cohen
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Hi, thanks for responding back to my message.

I don't need root access I think, I am just trying to create a new
directory for each new user that matches a username they choose while
signing up from our website. We create a new jad file which is for their
java enabled cell phone. We are able to create the file using
StreamWriter and File.Create(), only the directory is giving us trouble.

The hosting company is not sure when we called them, they said they were
researching it. I have tried to use the
\\SERVER\OURUSERACCOUNTNAME\DIRECTORY but that gives us the message:
System.IO.DirectoryNotFoundException: Could not find a
part of the path "D:\". at System.IO.__Error.WinIOError
(Int32 errorCode, String str) at
System.IO.Directory.InternalCreateDirectory(String
fullPath, String path) at System.IO.DirectoryInfo.Create
() at testapps.createdir.CreateSubDirectory(String direc)

We are really not sure what to do next. Seems like the
d:\inetput\wwwroot\OURUSERACCOUNTNAME\wwwRoot\jads which works when we
use the File.Create(PATH) does not work here.

Thanks for all the help so far, any more would be great.

Sheldon Cohen

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi, thanks for responding back to my message.

I don't need root access I think, I am just trying to create a new
directory for each new user that matches a username they choose while
signing up from our website. We create a new jad file which is for their
java enabled cell phone. We are able to create the file using
StreamWriter and File.Create(), only the directory is giving us trouble.

The hosting company is not sure when we called them, they said they were
researching it. I have tried to use the
\\SERVER\OURUSERACCOUNTNAME\DIRECTORY but that gives us the message:
System.IO.DirectoryNotFoundException: Could not find a
part of the path "D:\". at System.IO.__Error.WinIOError
(Int32 errorCode, String str) at
System.IO.Directory.InternalCreateDirectory(String
fullPath, String path) at System.IO.DirectoryInfo.Create
() at testapps.createdir.CreateSubDirectory(String direc)

We are really not sure what to do next. Seems like the
d:\inetput\wwwroot\OURUSERACCOUNTNAME\wwwRoot\jads which works when we
use the File.Create(PATH) does not work here.

Thanks for all the help so far, any more would be great.

Sheldon Cohen

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I think the problem may be share permissions. I had this problem once myself
where the root directory required directory read access or else shares
weren't accessible. I can't remember the details now exactly, but ultimately
it ended up being that I added EveryOne with directory read rights on the
root dir...

Bummer that htis is at an ISP which will make experimenting and trying to
find this issue a lot more work than if you can try it yourself <g
+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
-----------
Making waves on the Web

"Sheldon Cohen" <shelman2@.hotmail.com> wrote in message
news:ezyH6tylDHA.2652@.TK2MSFTNGP09.phx.gbl...
> Hi, thanks for responding back to my message.
> I don't need root access I think, I am just trying to create a new
> directory for each new user that matches a username they choose while
> signing up from our website. We create a new jad file which is for their
> java enabled cell phone. We are able to create the file using
> StreamWriter and File.Create(), only the directory is giving us trouble.
> The hosting company is not sure when we called them, they said they were
> researching it. I have tried to use the
> \\SERVER\OURUSERACCOUNTNAME\DIRECTORY but that gives us the message:
> System.IO.DirectoryNotFoundException: Could not find a
> part of the path "D:\". at System.IO.__Error.WinIOError
> (Int32 errorCode, String str) at
> System.IO.Directory.InternalCreateDirectory(String
> fullPath, String path) at System.IO.DirectoryInfo.Create
> () at testapps.createdir.CreateSubDirectory(String direc)
> We are really not sure what to do next. Seems like the
> d:\inetput\wwwroot\OURUSERACCOUNTNAME\wwwRoot\jads which works when we
> use the File.Create(PATH) does not work here.
> Thanks for all the help so far, any more would be great.
> Sheldon Cohen
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
I think the problem may be share permissions. I had this problem once myself
where the root directory required directory read access or else shares
weren't accessible. I can't remember the details now exactly, but ultimately
it ended up being that I added EveryOne with directory read rights on the
root dir...

Bummer that htis is at an ISP which will make experimenting and trying to
find this issue a lot more work than if you can try it yourself <g
+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
-----------
Making waves on the Web

"Sheldon Cohen" <shelman2@.hotmail.com> wrote in message
news:ezyH6tylDHA.2652@.TK2MSFTNGP09.phx.gbl...
> Hi, thanks for responding back to my message.
> I don't need root access I think, I am just trying to create a new
> directory for each new user that matches a username they choose while
> signing up from our website. We create a new jad file which is for their
> java enabled cell phone. We are able to create the file using
> StreamWriter and File.Create(), only the directory is giving us trouble.
> The hosting company is not sure when we called them, they said they were
> researching it. I have tried to use the
> \\SERVER\OURUSERACCOUNTNAME\DIRECTORY but that gives us the message:
> System.IO.DirectoryNotFoundException: Could not find a
> part of the path "D:\". at System.IO.__Error.WinIOError
> (Int32 errorCode, String str) at
> System.IO.Directory.InternalCreateDirectory(String
> fullPath, String path) at System.IO.DirectoryInfo.Create
> () at testapps.createdir.CreateSubDirectory(String direc)
> We are really not sure what to do next. Seems like the
> d:\inetput\wwwroot\OURUSERACCOUNTNAME\wwwRoot\jads which works when we
> use the File.Create(PATH) does not work here.
> Thanks for all the help so far, any more would be great.
> Sheldon Cohen
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Trouble Declaring and Setting Variable

I have a page that sends the value of a textbox in a form through GET.

My next page is supposed to grab that value, and put it in a variable. This is what I have for my next page:

1<%@dotnet.itags.org. Import namespace="System.IO"%>2<html>
3<head>
4<title>Uploading a File</title>
5678<script language="VB" runat="server">
9Dim strPath
10 strPath = Request.QueryString("path")
11
12 Dim savePath As String = StrPath
13Sub Upload_Click(source As Object, e As EventArgs)
1415 If Not (uploadedFile.PostedFile Is Nothing) Then
16 Try
17 Dim postedFile = uploadedFile.PostedFile
18 Dim filename As String = Path.GetFileName(postedFile.FileName)
19 Dim contentType As String = postedFile.ContentType
20 Dim contentLength As Integer = postedFile.ContentLength
2122 postedFile.SaveAs(savePath & filename)
23 message.Text = postedFile.Filename & " uploaded" & _
24 "<br>content type: " & contentType & _
25 "<br>content length: " & contentLength.ToString()
26 Catch exc As Exception
27 message.Text = "Failed uploading file"
28 End Try
29 End If
30End Sub
31</script>
32
33</head>
34<body>
35
36<form id="Form1" enctype="multipart/form-data" runat="server">
37 Select File to Upload:
3839 <input id="uploadedFile" type="file" runat="server">
40 <p>
41 <input type=button id="upload"
42 value="Upload"
43 OnServerClick="Upload_Click"
44 runat="server">
45 <p>
46 <asp:Label id="message" runat="server"/>
47</form>
48
49</body>
50</html>

I get a "declaration expected" on line 10. Any Ideas why?

A simle fix is to move both lines

Dim strPath as String = Request.QueryString("path")
Dim savePath As String = StrPath

to the top of Sub Upload_Click.


The actual error is that line 9 is not complete with a type declaration.

Dim strPathAs String

Also, you don't seem to need both strPath and savePath.

Dim savePath As String = Request.QueryString("path")
should be enough 


Gunteman, I must respectfully disagree. If you put

Dim savePath As String = Request.QueryString("path")

outside of Sub Upload_Click, you get the following exception:

"Request is not available in this context."

However, removing strPath does make sense.


Thanks to both of you. I still got a problem even after doing that, but adding "Context." before "Request" cleared things up.


louis210:

Gunteman, I must respectfully disagree. If you put

Dim savePath As String = Request.QueryString("path")

outside of Sub Upload_Click, you get the following exception:

"Request is not available in this context."

Quite right!

Monday, March 26, 2012

Trouble posting to Database from Drop Down List and Text box

I'm having real trouble posting from the webpage back to a database. This is supposed to be one of the easiest things to do in ASP.NET. I've checked viewstate on all of the controls and at the page level and all are set to true.

When I type in some text information, no other characters but plane text, and hit the submit button the text disappears from the box, the drop downlist returns to default, the subroutine runs and an empty space is submitted to the database.

I've verified that the procedure in my namespace is running correctly by allowing the subroutine in the code behind to trigger the SPROC in the namespace. The 'hardcoded' values are inserted into the database.

I also placed a label.text = textbox.text into the subroutine and it is always set to a blank. Even on page intialization. None the less, I wanted to see if running the subroutine would place text inside of the label and it didn't. If I hard code the label, such as label.text = "stanley" then stanley appears when you click the link button. Thus, I'm sure that the subroutine is running, its appears that the text in the text box is being lost when the page makes a round trip.

Any ideas?

SethLet's see your code.
Be sure that you are wrapping any code that initializes the values textbox and dropdownlist in your Page_Load with a check for IsPostBack:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'Initialize initial values of textbox and dropdownlist here
End If
End Sub

If you don't, each time the page postsback, the controls will be reset back to their initial state, probably blank for the textbox and no selected item for the drop down list. Remember that when the page posts back, Page_Load will run BEFORE any of the web control event handlers.

Saturday, March 24, 2012

Trouble sending email with ASP.NET 2.0

I have an ASP.NET 2.0 application that is supposed to send an email after a
certain form is submitted. When it tries to send the email, I receive the
following error:
Transaction failed. The server response was: njsokalski@dotnet.itags.org.hotmail.com:
Recipient address rejected: Access denied
(in the error message, the part with the email address was displayed as
<myemailaddress>, but you will probably see a link because our news viewers
think they know what we want). I know that the address is correct, so what
is it that the server didn't like about it? Is it saying I don't have
permission to use the SMTP server (I was pretty sure I was, but this is the
first time I am sending email from this server)? Is there something wrong
with my code? Any help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/On Fri, 5 Jan 2007 03:55:44 -0500, "Nathan Sokalski"
<njsokalski@.hotmail.com> wrote:

> Is there something wrong
>with my code? Any help would be appreciated. Thanks.
You didn't provide your code, so it is hard to tell.
However, this works for me:
Try
Dim mail As New Mail.MailMessage()
mail.From = New Mail.MailAddress("mail@.mail.somewhere",
"Subject")
mail.To.Add("another@.mail.somewhere")
mail.Subject = "Subject"
mail.Body = "Body"
Dim smtp As New Mail.SmtpClient("mail.planprojekt.dk")
smtp.Credentials = New
NetworkCredential("mail@.mail.somewhere", "password")
smtp.Send(mail)
bEmailSent = True
Catch ex As Exception
Exit Sub
End Try
/Snedker
If you are using the machine's local SMTP Service,
you may need to add a Smarthost or domains (e.g., "*.com", "*.net")
so that email sent through it is allowed to be sent out or relayed.
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Nathan Sokalski" wrote:

> I have an ASP.NET 2.0 application that is supposed to send an email after
a
> certain form is submitted. When it tries to send the email, I receive the
> following error:
>
> Transaction failed. The server response was: njsokalski@.hotmail.com:
> Recipient address rejected: Access denied
>
> (in the error message, the part with the email address was displayed as
> <myemailaddress>, but you will probably see a link because our news viewer
s
> think they know what we want). I know that the address is correct, so what
> is it that the server didn't like about it? Is it saying I don't have
> permission to use the SMTP server (I was pretty sure I was, but this is th
e
> first time I am sending email from this server)? Is there something wrong
> with my code? Any help would be appreciated. Thanks.
> --
> Nathan Sokalski
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/
>
>
The code I am using is as follows:
Private Sub SendEmailNotification()
Dim confsender As New
SmtpClient(System.Configuration.ConfigurationManager.AppSettings("smtpserver
"))
Dim confirmation As New MailMessage()
confirmation.IsBodyHtml = False
confirmation.From = New MailAddress("fromaddress@.mydomain.com")
confirmation.To.Add("njsokalski@.hotmail.com")
confirmation.Subject = "My Subject"
confirmation.Body = "My Body"
confsender.Send(confirmation)
End Sub
Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:2p6sp2dqb6qkfg0j60i3gt12iqvhdgcj70@.
4ax.com...
> On Fri, 5 Jan 2007 03:55:44 -0500, "Nathan Sokalski"
> <njsokalski@.hotmail.com> wrote:
>
> You didn't provide your code, so it is hard to tell.
> However, this works for me:
> Try
> Dim mail As New Mail.MailMessage()
> mail.From = New Mail.MailAddress("mail@.mail.somewhere",
> "Subject")
> mail.To.Add("another@.mail.somewhere")
> mail.Subject = "Subject"
> mail.Body = "Body"
> Dim smtp As New Mail.SmtpClient("mail.planprojekt.dk")
> smtp.Credentials = New
> NetworkCredential("mail@.mail.somewhere", "password")
> smtp.Send(mail)
> bEmailSent = True
> Catch ex As Exception
> Exit Sub
> End Try
>
> /Snedker

Trouble sending email with ASP.NET 2.0

I have an ASP.NET 2.0 application that is supposed to send an email after a
certain form is submitted. When it tries to send the email, I receive the
following error:

Transaction failed. The server response was: njsokalski@dotnet.itags.org.hotmail.com:
Recipient address rejected: Access denied

(in the error message, the part with the email address was displayed as
<myemailaddress>, but you will probably see a link because our news viewers
think they know what we want). I know that the address is correct, so what
is it that the server didn't like about it? Is it saying I don't have
permission to use the SMTP server (I was pretty sure I was, but this is the
first time I am sending email from this server)? Is there something wrong
with my code? Any help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/On Fri, 5 Jan 2007 03:55:44 -0500, "Nathan Sokalski"
<njsokalski@.hotmail.comwrote:

Quote:

Originally Posted by

Is there something wrong
>with my code? Any help would be appreciated. Thanks.


You didn't provide your code, so it is hard to tell.

However, this works for me:

Try
Dim mail As New Mail.MailMessage()

mail.From = New Mail.MailAddress("mail@.mail.somewhere",
"Subject")
mail.To.Add("another@.mail.somewhere")

mail.Subject = "Subject"
mail.Body = "Body"

Dim smtp As New Mail.SmtpClient("mail.planprojekt.dk")
smtp.Credentials = New
NetworkCredential("mail@.mail.somewhere", "password")
smtp.Send(mail)

bEmailSent = True
Catch ex As Exception
Exit Sub
End Try

/Snedker
The code I am using is as follows:

Private Sub SendEmailNotification()
Dim confsender As New
SmtpClient(System.Configuration.ConfigurationManag er.AppSettings("smtpserver"))
Dim confirmation As New MailMessage()
confirmation.IsBodyHtml = False
confirmation.From = New MailAddress("fromaddress@.mydomain.com")
confirmation.To.Add("njsokalski@.hotmail.com")
confirmation.Subject = "My Subject"
confirmation.Body = "My Body"

confsender.Send(confirmation)
End Sub

Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:2p6sp2dqb6qkfg0j60i3gt12iqvhdgcj70@.4ax.com...

Quote:

Originally Posted by

On Fri, 5 Jan 2007 03:55:44 -0500, "Nathan Sokalski"
<njsokalski@.hotmail.comwrote:
>

Quote:

Originally Posted by

>Is there something wrong
>>with my code? Any help would be appreciated. Thanks.


>
You didn't provide your code, so it is hard to tell.
>
However, this works for me:
>
Try
Dim mail As New Mail.MailMessage()
>
mail.From = New Mail.MailAddress("mail@.mail.somewhere",
"Subject")
mail.To.Add("another@.mail.somewhere")
>
mail.Subject = "Subject"
mail.Body = "Body"
>
Dim smtp As New Mail.SmtpClient("mail.planprojekt.dk")
smtp.Credentials = New
NetworkCredential("mail@.mail.somewhere", "password")
smtp.Send(mail)
>
bEmailSent = True
Catch ex As Exception
Exit Sub
End Try
>
>
/Snedker