Classic ASP getPathName and getName Error - asp-classic

I usually developed website using PHP. But now i have to using ASP Classic because my client already have a website then i have to maintenance the website. i already move all of the website to my new hosting. But there is error on this code :
cPath=getPathName(Server.mappath(Request.ServerVariables("PATH_INFO")))
The error message is :
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'getPathName'
Some error display when call getName code.
Please help me what should i do.

Classic ASP or VBScript do not have equivalent to the PHP getPathName() and getName() functions as far as I can tell.
I wasn't able to understand what's the meaning of getPathName() when it's given a string and actually I don't think it exists, so just have:
cPath = Server.MapPath(Request.ServerVariables("PATH_INFO"))
And the variable will contain the full physical path to the currently executing ASP file.
As for getName() you can write custom function:
Function GetOnlyName(filePath)
Dim slashIndex
slashIndex = InStrRev(filePath, "\")
If slashIndex<1 Then
slashIndex = InStrRev(filePath, "/")
End If
If slashIndex>0 Then
ExtractFileName = Mid(filePath, slashIndex + 1, Len(filePath) - slashIndex + 1)
Else
ExtractFileName = filePath
End If
End Function
Then use it like this:
cName = GetOnlyName(Server.MapPath(Request.ServerVariables("PATH_INFO")))
And the variable will contain only the name of the ASP file.
For the record, to avoid confusing Type Mismatch errors, always put this on top of your scripts:
Option Explicit
Then always declare all your variable using Dim statement, like in the function above. Having this, trying to use getPathName would give "variable undefined" error which is much more meaningful.

Related

typeof equivalent of .NET for ABL Progress Openedge

I have added System.Messaging to my assemblies.xml cause I need to use this in my Progress OpenEdge application. However I ran into a problem.
In C# when assigning:
m.Formatter = new XmlMessageFormatter(new[] { typeof(TrowConfiguration) });
TrowConfiguration myConfiguration = m.Body as TrowConfiguration;
However I now want to do this in ABL. I first used a method to read a string and just passed a CHARACTER EXTENT 1 INITIAL "System.String" to the XmlMessageFormatter object. However I tried changing this to the path of my object, TrowConfiguration, but this doesn't work and gives me an error.
If you're looking for the System.Type reference, use
Progress.Util.TypeHelper:GetType ("<your fully qualified type name>").

Why is TrimStart not recognised in VisualStudio for ASP.NET?

I whant to use TrimStart for my string value like this: How to remove all zeros from string's beginning?
But TrimStart syntax is not recognise in VisualStudio. How to corectly generate it?
my code:
string str = parameters.Internal;
string s = str;
string no_start_zeros = s.TrimStart('0');
At the top of your .CS file do you have: using system; the string.TrimStart(); method is found in the system namespace, which is contained inside mscorlib.dll - you can also try referencing mscorlib.dll directly.
TrimStart() function is used to Removes all leading occurrences of a set of characters specified in an array from the current String object.
when visual studio version you are using ? as far as I know trimStart() support in almost all version from 1.1 to 4.5
check out below snippet for more detail
string szInput = "000YTHLKJH";
string output = szInput.TrimStart('0');
//output will be : YTHLKJH
Hope it helps

The session state Information is invalid and might be corrupted in ASP.Net

I am using ASP.Net 3.5 with C#,Development ID:Visual Studio 2008. When I am using
Session["FileName1"] = "text1.txt"
it is working fine, but then I am using
number1=17;
string FileName1="FileName1" + number1.toString();
then setting with
Session[FileName1]="text1.txt";
gives me runtime error
The session state information is invalid and might be corrupted
at System.Web.SessionState.SessionStateItemCollection.Deserializer(BinaryReader reader)
Can anybody solve my problem, when I am using string in the Session variable? Remember it works on my development machine (meaning local Visual Studio) but when deployed to the server it gives mentioned error.
Make sure the FileName1 variable is not null before trying to access it via the Session[FileName1] syntax...
Here's a link to someone else that was having the same problem:
http://forums.asp.net/t/1069600.aspx
Here's his answer:
In the code, I found the following line:
//some code
Session.Add(sessionVarName, sessionVarValue);
//some other code
Apparently, because of some dirty data, there is a time when
sessionVarName is null.
Session.Add will not throw any exception in this case, and if your
Session Mode is "InProc", there will be no problem. However, if your
Session Mode is "SQLServer", during deserialization of the session
store, you will got the exception that I got. So, to filter out dirty
data, I modified the code to become:
if (sessionVarName != null)
{
//somecode
Session.Add(sessionVarName, sessionVarValue);
//some other code
}
the reason of your error is
xyz = new Guid() is also xyz= Guid.Empty;
so when you try to convert to string it's throw error.
just modify you code something like that.
Guid guId = System.Guid.NewGuid();
string x = guId .ToString();
string FileName1="text1.txt" + x;
Session[FileName1]="text1.txt";
Check your values before storing them in session they may cause this exception during deserialization of the session store, Filter your data .
Check Here
if(!string.IsNullOrEmpty(FileName1))
{
Session.Add(FileName1, "text1.txt");
}
Or check for Invalid characters in your string .
You can add the Value into session Like this
string FileName1="FileName1" + number1.toString();
if(!string.IsNullOrEmpty(FileName1))
{
Session.Add(FileName1, "text1.txt");
}

VB.net "'Me' is valid only within an instance method" inside PageMethods

I'm getting "Me' is valid only within an instance method" error when I convert function to a PageMethods.
Private Shared objDT As System.Data.DataTable
Private Shared objDR As System.Data.DataRow
<WebMethod()> Public Shared Function addstn(itemID As String) As String
For Each Me.objDR In objDT.Rows
If objDR("ProductID") = ProductID Then
If objDR("Options") = desc Then
objDR("Quantity") += 1
blnMatch = True
Exit For
End If
End If
Next
End Function
If I remove Me, I get different error.
I got this shopping cart script somewhere online and I'm not sure what to replace "Me.objDR" with something else.
Thank you in advance
The Me keyword provides a way to refer to the specific instance of a class or structure in which the code is currently executing.
In a shared context there is no instance. You can reference your variable directly or via ClassName.VariableName.
This could work(i'm not sure wherefrom the other variables are):
For Each objDR In objDT.Rows
If ProductID.Equals(objDR("ProductID")) _
AndAlso desc.Equals(objDR("Options"))Then
Dim q = CInt(objDR("Quantity"))
objDR("Quantity") = q + 1
blnMatch = True
Exit For
End If
Next
http://msdn.microsoft.com/en-us/library/20fy88e0%28v=vs.80%29.aspx
Me cannot be used since its a shared method, shared methods are not accessed through an instance.
What is the other error you receive?
Public Shared Function addstn(...
The "Shared" means it's not an instance method. If you want to use "Me", you can't use "Shared". Use the name of the class/module instead.

How to override VBScript GetObject method in .NET

I am having below code in VBScript
' Retrieve the keyword category for page section names
Set SectionCat = TDSE.GetObject(WebdavToUri(getPublicationWebDav(WEBDAV_SECTION_CAT)), 1)
' Retrieve the localized section keyword
Set SectionKeyword = SectionCat.GetKeywordByTitle(meta)
' Open the English translated section keyword
Set SectionKeyword = TDSE.GetObject(SectionKeyword.Id, 1, WEBDAV_UKEN_PUB)
SectionName = SectionKeyword.Title
Where WEBDAV_UKEN_PUB is the WebDavPath, now in VBScript GetObject method we have got option to pass three parameters 1) Item.ID, 2) TDSDefines.OpenModeEditWithFallback and 3) WebDavPath from where to make the object.
Now I want to write same logic in 2009 .Net templating, below is the sample code, I am trying to write but not able to get rid of VBScript Object.
Category cat = engine.GetSession().GetObject(WebdavToUri(getPublicationWebDav(Constants.WEBDAV_SECTION_CAT,package,engine), engine)) as Category;
if (cat != null)
{
//_log.Info("Category" + cat.Title);
Keyword keyword = cat.GetKeywordByTitle(meta);
//_log.Info("keyword 1" + keyword.Title);
keyword = engine.GetObject(Constants.WEBDAV_UKEN_PUB) as Keyword;
//_log.Info("keyword 2 " + keyword.Title);
if (keyword != null)
{
sectionName = keyword.Title;
}
keyword = null;
I am able to create Category object, however when I am trying to make Keyword object its getting failed and giving object reference error.
Do we have any class or method which work same like VBScript GetObject which will make the Object from the passed webdavpath or can somebody can give sample code on this.
I think your problem is here:
keyword = engine.GetObject(Constants.WEBDAV_UKEN_PUB) as Keyword;
You are using the WEBDav URL of a publication, and then attempting a dynamic cast to Keyword. You can't cast a Publication to a Keyword, so the cast fails and your keyword variable is assigned null.
Using dynamic casts in this way is an easy way to fool yourself. The "As" keyword (C# keyword not Tridion keyword) should be used when you don't know at compile time what type you expect. If you know that you expect an item of type Keyword, then you should write:
keyword = (Keyword)engine.GetObject(Constants.WEBDAV_UKEN_PUB);
This way - when the cast fails, you'll get an exception that identifies the problem correctly.
In TOM.NET we cannot get an object and specify which pub to read it from, we need to modify the TcmUri to be in context.
So:
Repository context = (Repository)session.GetObject(WEBDAV_UKEN_PUB);
TcmUri keywordInContext = new TcmUri(keyword.Id.ItemId, keyword.Id.ItemType, context.Id.ItemId);
Keyword keyword = (Keyword)session.GetObject(keywordInContext);

Resources