|
Let me explain.
GetExcludeFolder() - Gets from XML folders that has to be excluded, that's ok.
To enable paging, first I have to fill the array and then display the data from an array as I did in foreach.
The problem code is if statesment.
It says if s.Name doesen't have any string that GetExcludeFolder() returns, then fill the array with this folder name otherwise dont fill array.
When I run this, I get all folder from wwwroot.
Iam confused, what Iam doing wrong?
protected override void Render(HtmlTextWriter writer)
{
int i = 0, j = 0;
DirectoryInfo dir = new DirectoryInfo(@"f:\inetpub\wwwroot\");
DirectoryInfo[] d = dir.GetDirectories("*");
foreach (DirectoryInfo s in d)
{
if (s.Name.IndexOf(GetExcludeFolder()) == -1)
{
directory[i, j] = s.Name.ToString();
directory[i, j + 1] = s.CreationTime.ToString();
i++;
}
}
Response.Write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%\">");
Response.Write("<tr>");
Response.Write("<td style=\"height: 25px; width: 50%;\">Folder name");
Response.Write("</td>");
Response.Write("<td style=\"height: 25px; width: 50%;\">Date created");
Response.Write("</td>");
Response.Write("</tr>");
j = 0;
for (i = currentPage * pageSize - pageSize; i < currentPage * pageSize; i++ )
{
Response.Write("<tr>");
Response.Write("<td style=\"height: 25px;\"><a href=\"http://localhost/" + directory[i, j] + "/\">" + directory[i,j]);
Response.Write("</a></td>");
Response.Write("<td style=\"height: 25px;\">" + directory[i,j + 1]);
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("<tr>");
Response.Write("<td style=\"height: 25px\" colspan=\"2\">");
Response.Write("1 2 3");
Response.Write("</td>");
Response.Write("</tr>");
Response.Write("</table>");
}
|
|
|
|
|
You use a lot of variables that you (hopefully?) have defined outside the method. For instance, where, when and how do you create the directory array?
What does the GetExcludeFolder() method return? Why do you use IndexOf to compare it with the Name property?
---
b { font-weight: normal; }
|
|
|
|
|
I said above what returns GetExcludeFolder()
GetExcludeFolder() - Gets from XML folders that has to be excluded, that's ok.
directory array is declared global to the class, like pageSize and currentPage.
I use IndexOf to see what folders I don't need to enter into the array so it checks if a s.Name is comprehended in string that GetExcludeFolder returns.
If so, don't add that folder name into the array.
One more thing. String that returns GetExcludeFolder is something like: aspnet_client;_vti_cnf;vti_pvt;_vti_script;_vti_text;
Hope this is understandable.
|
|
|
|
|
Kasic Slobodan wrote: I said above what returns GetExcludeFolder()
GetExcludeFolder() - Gets from XML folders that has to be excluded, that's ok.
That information is not clear enough to determine the cause of the error. If the method actually returns more than one folder name, then your code doesn't make sense. That's also why I asked why you are using IndexOf.
Kasic Slobodan wrote: One more thing. String that returns GetExcludeFolder is something like: aspnet_client;_vti_cnf;vti_pvt;_vti_script;_vti_text;
Then you should look in that string for the folder name, not the other way around.
---
b { font-weight: normal; }
|
|
|
|
|
One more thing. String that returns GetExcludeFolder is something like: aspnet_client;_vti_cnf;vti_pvt;_vti_script;_vti_text;
Then your code is basically running the following...
if (s.Name.IndexOf("aspnet_client;_vti_cnf;vti_pvt;_vti_script;_vti_text;") == -1)
{<br />
directory[i, j] = s.Name.ToString();<br />
directory[i, j + 1] = s.CreationTime.ToString();<br />
i++;<br />
}
It's looking for the entire string of 'aspnet_client;_vti_cnf;vti_pvt;_vti_script;_vti_text;' inside your folder name for each folder and obviouly not finding it, and thus return ALL directories. You need to put the excluded folder names in some form of array then iterate through the array inside your foreach (DirectoryInfo s in d) checking ifthe current directory has been excluded. Hope that makes sense.
Sunday Ironfoot
www.dominicpettifer.co.uk (work in progress)
|
|
|
|
|
Here's a rewrite of your code....
protected override void Render(HtmlTextWriter writer)
{
int i = 0, j = 0;
DirectoryInfo dir = new DirectoryInfo(@"f:\inetpub\wwwroot\");
DirectoryInfo[] d = dir.GetDirectories("*");
String[] excludedFolders = { "aspnet_client", "_vti_cnf", "vti_pvt", "_vti_script", "_vti_text" };
foreach (DirectoryInfo s in d)
{
foreach(String folderToExclude in excludedFolders)
{
if (s.Name.IndexOf(folderToExclude) == -1)
{
directory[i, j] = s.Name.ToString();
directory[i, j + 1] = s.CreationTime.ToString();
i++;
}
}
}
}
There may be a better way to write it rather than use multiple nested for loops, but that should work.
The 'excludedFolders' String array could get it's contents from your function ie.
String[] excludedFolders = GetExcludeFolder();
...making sure GetExcludeFolder() method returns an array of strings.
Sunday Ironfoot
www.dominicpettifer.co.uk (work in progress)
|
|
|
|
|
@ Guffa
When I write if like: if (GetExcludeFolder().IndexOf(s.Name) == -1)
then all folder that GetExcludeFolder return arent added to array except two.
Iam confused, becouse I have done this planty of time, but reverse, not to exclude, but to include and this worked perfectly with the IndexOf method.
I don't know why that doesent work.
This is that method i was telling you about:
tFileTypes.Text = .zip;.rar;.exe;
and this is if
if (tFileTypes.Text.IndexOf(fi.Extension.ToString()) >= 0) // fi is in foreach, FileInfo
And this works. Its the same method, but the other condition.
I will use your code becouse I dont have a patience to experiment anymore.
Thank you both.
|
|
|
|
|
When I write if like: if (GetExcludeFolder().IndexOf(s.Name) == -1)
then all folder that GetExcludeFolder return arent added to array except two.
That should work, maybe want to check the string variable contents, maybe a space or something is being added somewhere it shouldn't, does your IDE (Visual Studio etc) have a debugger?
The only problem with that though is that the GetExcludeFolder() method is being called multiple times, once in each 'foreach' loop depending on how many directories there are. If the 'GetExcludeFolder()' method is fairly resource intensive (reading the file system for instance), the code I gave you using string arrays may be more efficient since 'GetExcludeFolder()' method is only being called once.
Good luck!
Sunday Ironfoot
www.dominicpettifer.co.uk (work in progress)
|
|
|
|
|
What folders are excluded that you think should be included?
---
b { font-weight: normal; }
|
|
|
|
|
I made a typo when I said that there is folders that are excluded, but it's not.
There is no directory named vti_pvt and _vti_text it should be _vti_pvt and _vti_txt .
Small typeo's, but makes a hell of a project .
I did a detailed debug nd saw this irregularity.
I did listen to Ironfoot and move GetExcludedFolder() out of the foreach.
But I didn't do as Ironafoot said with two for's becouse it would be hard to create an array from one string that is read from Xml.
Replaced array with ArrayList becouse I need dynamic array and now code, that works, looks like this:
protected override void Render(HtmlTextWriter writer)
{
string tmp = GetExcludeFolder();
int i = 0;
DirectoryInfo dir = new DirectoryInfo(GetWwwRootFolder());
DirectoryInfo[] d = dir.GetDirectories("*");
foreach (DirectoryInfo s in d)
{
if (tmp.IndexOf(s.Name) == -1)
{
directory.Add(s.Name.ToString());
date.Add(s.CreationTime.ToString());
i++;
}
}
Response.Write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
Response.Write("<tr>");
Response.Write("<td style=\"height: 25px; width: 50%;\">Folder name");
Response.Write("</td>");
Response.Write("<td style=\"height: 25px; width: 50%;\">Date created");
Response.Write("</td>");
Response.Write("</tr>");
for (i = currentPage * pageSize - pageSize + 1; i <= currentPage * pageSize; i++ )
{
if (i >= directory.Count)
break;
Response.Write("<tr>");
Response.Write("<td style=\"height: 25px;\"><a href=\"http://localhost/" + directory[i - 1] + "/\">" + directory[i - 1]);
Response.Write("</a></td>");
Response.Write("<td style=\"height: 25px;\">" + date[i - 1]);
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("<tr>");
Response.Write("<td style=\"height: 25px\" colspan=\"2\"><div align=\"" + GetPagingAlign() + "\" id=\"CustomPageAlign\">");
Response.Write("Choose page: ");
int mat = (int)Math.Ceiling((decimal)directory.Count / pageSize);
for (i = 1; i <= mat; i++)
{
if (i == currentPage)
{
Response.Write(i + " | ");
}
else
{
Response.Write("<a href=\"Default.aspx?Page=" + i + "\">" + i + "</a> | ");
}
}
Response.Write("</div></td>");
Response.Write("</tr>");
Response.Write("</table>");
}
It always helps me to see a bug if I talk to someone (forums, mails, etc.). I get a good code's that I can use and with talking, I can see some bugs that I could never see if I wasn't wrote this thread and ask you.
Thank you both for your time. I appreciated.
|
|
|
|
|
How do i upload images on to specified web pages?
thank you
Nothing lasts but nothing is lost
|
|
|
|
|
|
|
Hi
I have 2 chekboxes and a submit button in asp.net 2.0
on first checkbox onclick event i wrote a javascript , that will check the other checkbox to true and disable it.
now when i submit the page , before submmiting the page i get the other check box as checked = false; but acctually i have done it checked= true; using javasccript
please help why this is happening as i need to the other checkbox as checked = true using javascript
deepak
|
|
|
|
|
If you disable a form field it won't be included in the data that is sent from the form.
---
b { font-weight: normal; }
|
|
|
|
|
i have installed IIS on my Windows XP normally.its working for
http://localhost/ but when i give a site like
http://localhost/paksite/Test.aspx
(its a test page i developed myself.name is obviously Test.aspx)
it give me back HTML and asp.net code as well. as u all know that server should not return asp.net code. it should only return html and html equivalent of asp.net code
|
|
|
|
|
Normally, the IIS needs installing before the .NET framework, otherwise it does not work properly. Also, when the ASP.NET is not properly set up, it may also cause the iissue, and in this case you can use the Aspnet_regiis.exe tool to reset the ASP.NET.
|
|
|
|
|
Hi guys
How you do add a report (rdl file) in a report viewer in asp.net 2.0?
|
|
|
|
|
Hi
I am using a label and a html select control in asp.net 2.0 , and writing a javascript to set the value of the selected index of select control in the label,
but i am getting nothing please help me
here is a small code i am using
function setForFrozen(isFrozen)
{
if(isFrozen == 'true' )
{
var selectedItem = document.getElementById("permddlCity").selectedIndex;
var selectedText = document.getElementById("permddlCity").options[selectedItem].text;
document.getElementById("ctl00_MainContent_ctl00_lblPermOtherCity").value = selectedText;
document.getElementById("ctl00_MainContent_ctl00_lblPermOtherCity").style.display ="block";
}
}
deepak
|
|
|
|
|
And what is happening when you try this? Is selectedText valid? Is the an error being generated? Are you just not getting the text to show up on the label?
We need a little more than "i am getting nothing"
only two letters away from being an asset
|
|
|
|
|
Hi Mark,
thanks for the efforts but i got the solution
I have to use innerHtml to get the text in DIV tag
as for the Label control .net renders is a DIV tag
stay blessed'
deepak
|
|
|
|
|
i wanna add a custom control to a webform in ASP.NET 1.1, and i've two problems:
(Hint: the custom control has some javascript code that i wrote in the same file *.ascx with the controls in this custom control)
1- when i add my custom control more than once in the webform, the javascript don't work att all,..(it's a rollover behavior)
2-i need to put a hidden field in this custom control that have a value which is ,set by the javascript code, AND accessed by the webform that have this custom control on it....
i know this sounds complicated, but i've no other choise
(hint: does anyone know any other way(s) to build the rating control (the filled stars) just like the one in yahoo video, to make a survey form, and with no postbacks)
thnx for ur help
Kariem
|
|
|
|
|
Create a composite control , in that use javascript something like this
if (MaxLength > 0 && TextMode == TextBoxMode.MultiLine)
{
// Add javascript handlers for paste and keypress
Attributes.Add("onkeypress", "doKeypress(this);");
Attributes.Add("onbeforepaste", "doBeforePaste(this);");
Attributes.Add("onpaste", "doPaste(this);");
// Add attribute for access of maxlength property on client-side
Attributes.Add("maxLength", this.MaxLength.ToString());
// Register client side include - only once per page
if (!Page.ClientScript.IsClientScriptIncludeRegistered("TextArea"))
{
Page.ClientScript.RegisterClientScriptInclude("TextArea", ResolveClientUrl("~/FSjavaScript/textArea.js"));
}
}
then u can use the control as many times u feel like , the scripts will not roll up
|
|
|
|
|
Hello.
I want to add a Control to my Page through the code-behind, and AFTER that, use the Response.Write cmd.
eg.:
Page.Controls.Add(Page.LoadControl("Top.Ascx"));
Response.Write("after");
Will this load the Control, and after the Control is loaded, it will write "after" or just the oposite?
If it is oposite, how can I fix it?
Thanks alot.
NaNg.
|
|
|
|
|
It will first add the control to the control collection of the page object, then it will write the text to the output stream. As the controls of the page is rendered to the output stream after the Page_Load (and Page_PreRender), the text will end up before the entire page, even before the <htlm> tag.
If you want to put text on the page, put it in a control, either one that you put on the page in advance, or one that you add to the page. A Literal control is suitable to put plain text on a page.
---
b { font-weight: normal; }
|
|
|
|